| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/audio_input_controller.h" | 5 #include "media/audio/audio_input_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 return NULL; | 43 return NULL; |
| 44 | 44 |
| 45 if (factory_) { | 45 if (factory_) { |
| 46 return factory_->Create(event_handler, params); | 46 return factory_->Create(event_handler, params); |
| 47 } | 47 } |
| 48 | 48 |
| 49 scoped_refptr<AudioInputController> controller(new AudioInputController( | 49 scoped_refptr<AudioInputController> controller(new AudioInputController( |
| 50 event_handler, NULL)); | 50 event_handler, NULL)); |
| 51 | 51 |
| 52 // Start the thread and post a task to create the audio input stream. | 52 // Start the thread and post a task to create the audio input stream. |
| 53 // Pass an empty string to indicate using default device. |
| 54 std::string device_id = AudioManagerBase::kDefaultDeviceId; |
| 53 controller->thread_.Start(); | 55 controller->thread_.Start(); |
| 54 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 56 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 55 &AudioInputController::DoCreate, controller.get(), params)); | 57 &AudioInputController::DoCreate, controller.get(), |
| 58 params, device_id)); |
| 56 return controller; | 59 return controller; |
| 57 } | 60 } |
| 58 | 61 |
| 59 // static | 62 // static |
| 60 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( | 63 scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( |
| 61 EventHandler* event_handler, | 64 EventHandler* event_handler, |
| 62 const AudioParameters& params, | 65 const AudioParameters& params, |
| 66 const std::string& device_id, |
| 63 SyncWriter* sync_writer) { | 67 SyncWriter* sync_writer) { |
| 64 DCHECK(sync_writer); | 68 DCHECK(sync_writer); |
| 65 | 69 |
| 66 if (!params.IsValid() || (params.channels > kMaxInputChannels)) | 70 if (!params.IsValid() || (params.channels > kMaxInputChannels)) |
| 67 return NULL; | 71 return NULL; |
| 68 | 72 |
| 69 if (!AudioManager::GetAudioManager()) | 73 if (!AudioManager::GetAudioManager()) |
| 70 return NULL; | 74 return NULL; |
| 71 | 75 |
| 72 // Starts the audio controller thread. | 76 // Starts the audio controller thread. |
| 73 scoped_refptr<AudioInputController> controller(new AudioInputController( | 77 scoped_refptr<AudioInputController> controller(new AudioInputController( |
| 74 event_handler, sync_writer)); | 78 event_handler, sync_writer)); |
| 75 | 79 |
| 76 // Start the thread and post a task to create the audio input stream. | 80 // Start the thread and post a task to create the audio input stream. |
| 77 controller->thread_.Start(); | 81 controller->thread_.Start(); |
| 78 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 82 controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 79 &AudioInputController::DoCreate, controller.get(), params)); | 83 &AudioInputController::DoCreate, controller.get(), params, device_id)); |
| 80 return controller; | 84 return controller; |
| 81 } | 85 } |
| 82 | 86 |
| 83 void AudioInputController::Record() { | 87 void AudioInputController::Record() { |
| 84 DCHECK(thread_.IsRunning()); | 88 DCHECK(thread_.IsRunning()); |
| 85 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 89 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 86 &AudioInputController::DoRecord, this)); | 90 &AudioInputController::DoRecord, this)); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void AudioInputController::Close() { | 93 void AudioInputController::Close() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 // This is because as joining threads may be a long operation it's now | 105 // This is because as joining threads may be a long operation it's now |
| 102 // not allowed in threads without IO access, which is the case of the IO | 106 // not allowed in threads without IO access, which is the case of the IO |
| 103 // thread (it is missnamed) being used here. This object overrides | 107 // thread (it is missnamed) being used here. This object overrides |
| 104 // temporarily this restriction and should be used only in specific | 108 // temporarily this restriction and should be used only in specific |
| 105 // infrequent cases where joining is guaranteed to be fast. | 109 // infrequent cases where joining is guaranteed to be fast. |
| 106 // Bug: http://code.google.com/p/chromium/issues/detail?id=67806 | 110 // Bug: http://code.google.com/p/chromium/issues/detail?id=67806 |
| 107 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 111 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |
| 108 thread_.Stop(); | 112 thread_.Stop(); |
| 109 } | 113 } |
| 110 | 114 |
| 111 void AudioInputController::DoCreate(const AudioParameters& params) { | 115 void AudioInputController::DoCreate(const AudioParameters& params, |
| 112 stream_ = AudioManager::GetAudioManager()->MakeAudioInputStream(params); | 116 const std::string& device_id) { |
| 117 stream_ = AudioManager::GetAudioManager()->MakeAudioInputStream(params, |
| 118 device_id); |
| 113 | 119 |
| 114 if (!stream_) { | 120 if (!stream_) { |
| 115 // TODO(satish): Define error types. | 121 // TODO(satish): Define error types. |
| 116 handler_->OnError(this, 0); | 122 handler_->OnError(this, 0); |
| 117 return; | 123 return; |
| 118 } | 124 } |
| 119 | 125 |
| 120 if (stream_ && !stream_->Open()) { | 126 if (stream_ && !stream_->Open()) { |
| 121 stream_->Close(); | 127 stream_->Close(); |
| 122 stream_ = NULL; | 128 stream_ = NULL; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // such cases here. | 215 // such cases here. |
| 210 } | 216 } |
| 211 | 217 |
| 212 void AudioInputController::OnError(AudioInputStream* stream, int code) { | 218 void AudioInputController::OnError(AudioInputStream* stream, int code) { |
| 213 // Handle error on the audio controller thread. | 219 // Handle error on the audio controller thread. |
| 214 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 220 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 215 &AudioInputController::DoReportError, this, code)); | 221 &AudioInputController::DoReportError, this, code)); |
| 216 } | 222 } |
| 217 | 223 |
| 218 } // namespace media | 224 } // namespace media |
| OLD | NEW |