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/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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 // audio-device thread. Use the provided audio-input device. | 94 // audio-device thread. Use the provided audio-input device. |
95 if (!controller->message_loop_->PostTask(FROM_HERE, | 95 if (!controller->message_loop_->PostTask(FROM_HERE, |
96 base::Bind(&AudioInputController::DoCreate, controller, | 96 base::Bind(&AudioInputController::DoCreate, controller, |
97 base::Unretained(audio_manager), params, device_id))) { | 97 base::Unretained(audio_manager), params, device_id))) { |
98 controller = NULL; | 98 controller = NULL; |
99 } | 99 } |
100 | 100 |
101 return controller; | 101 return controller; |
102 } | 102 } |
103 | 103 |
104 // static | |
105 scoped_refptr<AudioInputController> AudioInputController::CreateForStream( | |
106 AudioManager* audio_manager, | |
107 EventHandler* event_handler, | |
108 AudioInputStream* stream, | |
109 SyncWriter* sync_writer) { | |
110 DCHECK(audio_manager); | |
111 DCHECK(sync_writer); | |
112 DCHECK(stream); | |
113 | |
114 // Create the AudioInputController object and ensure that it runs on | |
115 // the audio-manager thread. | |
116 scoped_refptr<AudioInputController> controller(new AudioInputController( | |
117 event_handler, sync_writer)); | |
118 controller->message_loop_ = audio_manager->GetMessageLoop(); | |
119 | |
120 controller->stream_ = stream; | |
DaleCurtis
2013/01/15 22:02:18
Seems like it might be clearer to make a DoCreate(
miu
2013/01/16 03:22:18
Done. I renamed DoFinishCreate() to DoCreateForSt
| |
121 | |
122 if (!controller->message_loop_->PostTask( | |
123 FROM_HERE, | |
124 base::Bind(&AudioInputController::DoFinishCreate, controller))) { | |
125 controller = NULL; | |
126 } | |
127 | |
128 return controller; | |
129 } | |
130 | |
104 void AudioInputController::Record() { | 131 void AudioInputController::Record() { |
105 message_loop_->PostTask(FROM_HERE, base::Bind( | 132 message_loop_->PostTask(FROM_HERE, base::Bind( |
106 &AudioInputController::DoRecord, this)); | 133 &AudioInputController::DoRecord, this)); |
107 } | 134 } |
108 | 135 |
109 void AudioInputController::Close(const base::Closure& closed_task) { | 136 void AudioInputController::Close(const base::Closure& closed_task) { |
110 DCHECK(!closed_task.is_null()); | 137 DCHECK(!closed_task.is_null()); |
111 DCHECK(creator_loop_->BelongsToCurrentThread()); | 138 DCHECK(creator_loop_->BelongsToCurrentThread()); |
112 | 139 |
113 message_loop_->PostTaskAndReply( | 140 message_loop_->PostTaskAndReply( |
(...skipping 10 matching lines...) Expand all Loading... | |
124 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); | 151 &AudioInputController::DoSetAutomaticGainControl, this, enabled)); |
125 } | 152 } |
126 | 153 |
127 void AudioInputController::DoCreate(AudioManager* audio_manager, | 154 void AudioInputController::DoCreate(AudioManager* audio_manager, |
128 const AudioParameters& params, | 155 const AudioParameters& params, |
129 const std::string& device_id) { | 156 const std::string& device_id) { |
130 DCHECK(message_loop_->BelongsToCurrentThread()); | 157 DCHECK(message_loop_->BelongsToCurrentThread()); |
131 | 158 |
132 stream_ = audio_manager->MakeAudioInputStream(params, device_id); | 159 stream_ = audio_manager->MakeAudioInputStream(params, device_id); |
133 | 160 |
161 DoFinishCreate(); | |
162 } | |
163 | |
164 void AudioInputController::DoFinishCreate() { | |
165 DCHECK(message_loop_->BelongsToCurrentThread()); | |
166 | |
134 if (!stream_) { | 167 if (!stream_) { |
135 // TODO(satish): Define error types. | 168 // TODO(satish): Define error types. |
136 handler_->OnError(this, 0); | 169 handler_->OnError(this, 0); |
137 return; | 170 return; |
138 } | 171 } |
139 | 172 |
140 if (stream_ && !stream_->Open()) { | 173 if (stream_ && !stream_->Open()) { |
141 stream_->Close(); | 174 stream_->Close(); |
142 stream_ = NULL; | 175 stream_ = NULL; |
143 // TODO(satish): Define error types. | 176 // TODO(satish): Define error types. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 343 |
311 void AudioInputController::SetDataIsActive(bool enabled) { | 344 void AudioInputController::SetDataIsActive(bool enabled) { |
312 base::subtle::Release_Store(&data_is_active_, enabled); | 345 base::subtle::Release_Store(&data_is_active_, enabled); |
313 } | 346 } |
314 | 347 |
315 bool AudioInputController::GetDataIsActive() { | 348 bool AudioInputController::GetDataIsActive() { |
316 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 349 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
317 } | 350 } |
318 | 351 |
319 } // namespace media | 352 } // namespace media |
OLD | NEW |