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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // also called when closing the input controller. | 240 // also called when closing the input controller. |
241 audio_manager_->DecreaseActiveInputStreamCount(); | 241 audio_manager_->DecreaseActiveInputStreamCount(); |
242 | 242 |
243 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. | 243 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. |
244 int error = wrapper_->PcmDrop(device_handle_); | 244 int error = wrapper_->PcmDrop(device_handle_); |
245 if (error < 0) | 245 if (error < 0) |
246 HandleError("PcmDrop", error); | 246 HandleError("PcmDrop", error); |
247 } | 247 } |
248 | 248 |
249 void AlsaPcmInputStream::Close() { | 249 void AlsaPcmInputStream::Close() { |
250 scoped_ptr<AlsaPcmInputStream> self_deleter(this); | 250 if (device_handle_) { |
| 251 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. |
| 252 int error = alsa_util::CloseDevice(wrapper_, device_handle_); |
| 253 if (error < 0) |
| 254 HandleError("PcmClose", error); |
251 | 255 |
252 // Check in case we were already closed or not initialized yet. | 256 if (mixer_handle_) |
253 if (!device_handle_) | 257 alsa_util::CloseMixer(wrapper_, mixer_handle_, device_name_); |
254 return; | |
255 | 258 |
256 weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. | 259 audio_packet_.reset(); |
257 int error = alsa_util::CloseDevice(wrapper_, device_handle_); | 260 device_handle_ = NULL; |
258 if (error < 0) | 261 mixer_handle_ = NULL; |
259 HandleError("PcmClose", error); | 262 mixer_element_handle_ = NULL; |
260 | 263 |
261 if (mixer_handle_) | 264 if (callback_) |
262 alsa_util::CloseMixer(wrapper_, mixer_handle_, device_name_); | 265 callback_->OnClose(this); |
| 266 } |
263 | 267 |
264 audio_packet_.reset(); | 268 audio_manager_->ReleaseInputStream(this); |
265 device_handle_ = NULL; | |
266 | |
267 if (callback_) | |
268 callback_->OnClose(this); | |
269 } | 269 } |
270 | 270 |
271 double AlsaPcmInputStream::GetMaxVolume() { | 271 double AlsaPcmInputStream::GetMaxVolume() { |
272 if (!mixer_handle_ || !mixer_element_handle_) { | 272 if (!mixer_handle_ || !mixer_element_handle_) { |
273 DLOG(WARNING) << "GetMaxVolume is not supported for " << device_name_; | 273 DLOG(WARNING) << "GetMaxVolume is not supported for " << device_name_; |
274 return 0.0; | 274 return 0.0; |
275 } | 275 } |
276 | 276 |
277 if (!wrapper_->MixerSelemHasCaptureVolume(mixer_element_handle_)) { | 277 if (!wrapper_->MixerSelemHasCaptureVolume(mixer_element_handle_)) { |
278 DLOG(WARNING) << "Unsupported microphone volume for " << device_name_; | 278 DLOG(WARNING) << "Unsupported microphone volume for " << device_name_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return 0.0; | 321 return 0.0; |
322 } | 322 } |
323 | 323 |
324 return static_cast<double>(current_volume); | 324 return static_cast<double>(current_volume); |
325 } | 325 } |
326 | 326 |
327 void AlsaPcmInputStream::HandleError(const char* method, int error) { | 327 void AlsaPcmInputStream::HandleError(const char* method, int error) { |
328 LOG(WARNING) << method << ": " << wrapper_->StrError(error); | 328 LOG(WARNING) << method << ": " << wrapper_->StrError(error); |
329 callback_->OnError(this, error); | 329 callback_->OnError(this, error); |
330 } | 330 } |
OLD | NEW |