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_device.h" | 5 #include "media/audio/audio_input_device.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // http://crbug.com/180640 | 171 // http://crbug.com/180640 |
172 switch (state) { | 172 switch (state) { |
173 case AUDIO_INPUT_IPC_DELEGATE_STATE_STOPPED: | 173 case AUDIO_INPUT_IPC_DELEGATE_STATE_STOPPED: |
174 ShutDownOnIOThread(); | 174 ShutDownOnIOThread(); |
175 break; | 175 break; |
176 case AUDIO_INPUT_IPC_DELEGATE_STATE_RECORDING: | 176 case AUDIO_INPUT_IPC_DELEGATE_STATE_RECORDING: |
177 NOTIMPLEMENTED(); | 177 NOTIMPLEMENTED(); |
178 break; | 178 break; |
179 case AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR: | 179 case AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR: |
180 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(ERROR)"; | 180 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(ERROR)"; |
181 // Don't dereference the callback object if the audio thread | 181 if (state_ == CREATING_STREAM) { |
182 // is stopped or stopping. That could mean that the callback | 182 // At this point, we haven't attempted to start the audio thread. |
183 // object has been deleted. | 183 // Accessing the hardware might have failed or we may have reached |
184 // TODO(tommi): Add an explicit contract for clearing the callback | 184 // the limit of the number of allowed concurrent streams. |
185 // object. Possibly require calling Initialize again or provide | 185 // We must report the error to the |callback_| so that a potential |
186 // a callback object via Start() and clear it in Stop(). | 186 // audio source object will enter the correct state (e.g. 'ended' for |
187 { | 187 // a local audio source). |
| 188 callback_->OnCaptureError( |
| 189 "Maximum allowed input device limit reached or OS failure."); |
| 190 } else { |
| 191 // Don't dereference the callback object if the audio thread |
| 192 // is stopped or stopping. That could mean that the callback |
| 193 // object has been deleted. |
| 194 // TODO(tommi): Add an explicit contract for clearing the callback |
| 195 // object. Possibly require calling Initialize again or provide |
| 196 // a callback object via Start() and clear it in Stop(). |
188 base::AutoLock auto_lock_(audio_thread_lock_); | 197 base::AutoLock auto_lock_(audio_thread_lock_); |
189 if (audio_thread_) { | 198 if (audio_thread_) |
190 callback_->OnCaptureError( | 199 callback_->OnCaptureError("AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR"); |
191 "AudioInputDevice::OnStateChanged - audio thread still running"); | |
192 } | |
193 } | 200 } |
194 break; | 201 break; |
195 default: | 202 default: |
196 NOTREACHED(); | 203 NOTREACHED(); |
197 break; | 204 break; |
198 } | 205 } |
199 } | 206 } |
200 | 207 |
201 void AudioInputDevice::OnIPCClosed() { | 208 void AudioInputDevice::OnIPCClosed() { |
202 DCHECK(task_runner()->BelongsToCurrentThread()); | 209 DCHECK(task_runner()->BelongsToCurrentThread()); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 capture_callback_->Capture( | 352 capture_callback_->Capture( |
346 audio_bus, | 353 audio_bus, |
347 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms | 354 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms |
348 buffer->params.volume, buffer->params.key_pressed); | 355 buffer->params.volume, buffer->params.key_pressed); |
349 | 356 |
350 if (++current_segment_id_ >= total_segments_) | 357 if (++current_segment_id_ >= total_segments_) |
351 current_segment_id_ = 0; | 358 current_segment_id_ = 0; |
352 } | 359 } |
353 | 360 |
354 } // namespace media | 361 } // namespace media |
OLD | NEW |