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/linux/alsa_input.h" | 5 #include "media/audio/linux/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.h" | 10 #include "base/message_loop.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } else { | 117 } else { |
118 // We start reading data half |buffer_duration_| later than when the | 118 // We start reading data half |buffer_duration_| later than when the |
119 // buffer might have got filled, to accommodate some delays in the audio | 119 // buffer might have got filled, to accommodate some delays in the audio |
120 // driver. This could also give us a smooth read sequence going forward. | 120 // driver. This could also give us a smooth read sequence going forward. |
121 base::TimeDelta delay = buffer_duration_ + buffer_duration_ / 2; | 121 base::TimeDelta delay = buffer_duration_ + buffer_duration_ / 2; |
122 next_read_time_ = base::Time::Now() + delay; | 122 next_read_time_ = base::Time::Now() + delay; |
123 base::MessageLoop::current()->PostDelayedTask( | 123 base::MessageLoop::current()->PostDelayedTask( |
124 FROM_HERE, | 124 FROM_HERE, |
125 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), | 125 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), |
126 delay); | 126 delay); |
127 | |
128 audio_manager_->IncreaseActiveInputStreamCount(); | |
129 } | 127 } |
130 } | 128 } |
131 | 129 |
132 bool AlsaPcmInputStream::Recover(int original_error) { | 130 bool AlsaPcmInputStream::Recover(int original_error) { |
133 int error = wrapper_->PcmRecover(device_handle_, original_error, 1); | 131 int error = wrapper_->PcmRecover(device_handle_, original_error, 1); |
134 if (error < 0) { | 132 if (error < 0) { |
135 // Docs say snd_pcm_recover returns the original error if it is not one | 133 // Docs say snd_pcm_recover returns the original error if it is not one |
136 // of the recoverable ones, so this log message will probably contain the | 134 // of the recoverable ones, so this log message will probably contain the |
137 // same error twice. | 135 // same error twice. |
138 LOG(WARNING) << "Unable to recover from \"" | 136 LOG(WARNING) << "Unable to recover from \"" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), | 234 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), |
237 delay); | 235 delay); |
238 } | 236 } |
239 | 237 |
240 void AlsaPcmInputStream::Stop() { | 238 void AlsaPcmInputStream::Stop() { |
241 if (!device_handle_ || !callback_) | 239 if (!device_handle_ || !callback_) |
242 return; | 240 return; |
243 | 241 |
244 StopAgc(); | 242 StopAgc(); |
245 | 243 |
246 // Stop is always called before Close. In case of error, this will be | |
247 // also called when closing the input controller. | |
248 audio_manager_->DecreaseActiveInputStreamCount(); | |
249 | |
250 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. | 244 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. |
251 int error = wrapper_->PcmDrop(device_handle_); | 245 int error = wrapper_->PcmDrop(device_handle_); |
252 if (error < 0) | 246 if (error < 0) |
253 HandleError("PcmDrop", error); | 247 HandleError("PcmDrop", error); |
254 } | 248 } |
255 | 249 |
256 void AlsaPcmInputStream::Close() { | 250 void AlsaPcmInputStream::Close() { |
257 if (device_handle_) { | 251 if (device_handle_) { |
258 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. | 252 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. |
259 int error = alsa_util::CloseDevice(wrapper_, device_handle_); | 253 int error = alsa_util::CloseDevice(wrapper_, device_handle_); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 331 |
338 return static_cast<double>(current_volume); | 332 return static_cast<double>(current_volume); |
339 } | 333 } |
340 | 334 |
341 void AlsaPcmInputStream::HandleError(const char* method, int error) { | 335 void AlsaPcmInputStream::HandleError(const char* method, int error) { |
342 LOG(WARNING) << method << ": " << wrapper_->StrError(error); | 336 LOG(WARNING) << method << ": " << wrapper_->StrError(error); |
343 callback_->OnError(this); | 337 callback_->OnError(this); |
344 } | 338 } |
345 | 339 |
346 } // namespace media | 340 } // namespace media |
OLD | NEW |