Chromium Code Reviews| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 DCHECK(!audio_thread_); | 148 DCHECK(!audio_thread_); |
| 149 audio_callback_.reset(new AudioInputDevice::AudioThreadCallback( | 149 audio_callback_.reset(new AudioInputDevice::AudioThreadCallback( |
| 150 audio_parameters_, handle, length, total_segments, callback_)); | 150 audio_parameters_, handle, length, total_segments, callback_)); |
| 151 audio_thread_.reset(new AudioDeviceThread(audio_callback_.get(), | 151 audio_thread_.reset(new AudioDeviceThread(audio_callback_.get(), |
| 152 socket_handle, "AudioInputDevice")); | 152 socket_handle, "AudioInputDevice")); |
| 153 | 153 |
| 154 state_ = RECORDING; | 154 state_ = RECORDING; |
| 155 ipc_->RecordStream(); | 155 ipc_->RecordStream(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void AudioInputDevice::OnVolume(double volume) { | 158 void AudioInputDevice::OnError() { |
|
tommi (sloooow) - chröme
2017/01/09 09:25:19
Nice, OnError makes a lot more sense :)
| |
| 159 NOTIMPLEMENTED(); | |
| 160 } | |
| 161 | |
| 162 void AudioInputDevice::OnStateChanged( | |
| 163 AudioInputIPCDelegateState state) { | |
| 164 DCHECK(task_runner()->BelongsToCurrentThread()); | 159 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 165 | 160 |
| 166 // Do nothing if the stream has been closed. | 161 // Do nothing if the stream has been closed. |
| 167 if (state_ < CREATING_STREAM) | 162 if (state_ < CREATING_STREAM) |
| 168 return; | 163 return; |
| 169 | 164 |
| 170 // TODO(miu): Clean-up inconsistent and incomplete handling here. | 165 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(ERROR)"; |
| 171 // http://crbug.com/180640 | 166 if (state_ == CREATING_STREAM) { |
| 172 switch (state) { | 167 // At this point, we haven't attempted to start the audio thread. |
| 173 case AUDIO_INPUT_IPC_DELEGATE_STATE_STOPPED: | 168 // Accessing the hardware might have failed or we may have reached |
| 174 ShutDownOnIOThread(); | 169 // the limit of the number of allowed concurrent streams. |
| 175 break; | 170 // We must report the error to the |callback_| so that a potential |
| 176 case AUDIO_INPUT_IPC_DELEGATE_STATE_RECORDING: | 171 // audio source object will enter the correct state (e.g. 'ended' for |
| 177 NOTIMPLEMENTED(); | 172 // a local audio source). |
| 178 break; | 173 callback_->OnCaptureError( |
| 179 case AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR: | 174 "Maximum allowed input device limit reached or OS failure."); |
| 180 DLOG(WARNING) << "AudioInputDevice::OnStateChanged(ERROR)"; | 175 } else { |
| 181 if (state_ == CREATING_STREAM) { | 176 // Don't dereference the callback object if the audio thread |
| 182 // At this point, we haven't attempted to start the audio thread. | 177 // is stopped or stopping. That could mean that the callback |
| 183 // Accessing the hardware might have failed or we may have reached | 178 // object has been deleted. |
| 184 // the limit of the number of allowed concurrent streams. | 179 // TODO(tommi): Add an explicit contract for clearing the callback |
| 185 // We must report the error to the |callback_| so that a potential | 180 // object. Possibly require calling Initialize again or provide |
| 186 // audio source object will enter the correct state (e.g. 'ended' for | 181 // a callback object via Start() and clear it in Stop(). |
| 187 // a local audio source). | 182 base::AutoLock auto_lock_(audio_thread_lock_); |
| 188 callback_->OnCaptureError( | 183 if (audio_thread_) |
| 189 "Maximum allowed input device limit reached or OS failure."); | 184 callback_->OnCaptureError("IPC delegate state error."); |
| 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(). | |
| 197 base::AutoLock auto_lock_(audio_thread_lock_); | |
| 198 if (audio_thread_) | |
| 199 callback_->OnCaptureError("AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR"); | |
| 200 } | |
| 201 break; | |
| 202 default: | |
| 203 NOTREACHED(); | |
| 204 break; | |
| 205 } | 185 } |
| 206 } | 186 } |
| 207 | 187 |
| 208 void AudioInputDevice::OnIPCClosed() { | 188 void AudioInputDevice::OnIPCClosed() { |
| 209 DCHECK(task_runner()->BelongsToCurrentThread()); | 189 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 210 state_ = IPC_CLOSED; | 190 state_ = IPC_CLOSED; |
| 211 ipc_.reset(); | 191 ipc_.reset(); |
| 212 } | 192 } |
| 213 | 193 |
| 214 AudioInputDevice::~AudioInputDevice() {} | 194 AudioInputDevice::~AudioInputDevice() {} |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 capture_callback_->Capture( | 332 capture_callback_->Capture( |
| 353 audio_bus, | 333 audio_bus, |
| 354 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms | 334 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms |
| 355 buffer->params.volume, buffer->params.key_pressed); | 335 buffer->params.volume, buffer->params.key_pressed); |
| 356 | 336 |
| 357 if (++current_segment_id_ >= total_segments_) | 337 if (++current_segment_id_ >= total_segments_) |
| 358 current_segment_id_ = 0; | 338 current_segment_id_ = 0; |
| 359 } | 339 } |
| 360 | 340 |
| 361 } // namespace media | 341 } // namespace media |
| OLD | NEW |