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_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 |
| 11 namespace { | 11 namespace { |
| 12 const int kMaxInputChannels = 2; | 12 const int kMaxInputChannels = 2; |
| 13 const int kTimerResetInterval = 1; // One second. | 13 const int kTimerResetIntervalSeconds = 1; |
| 14 #if defined(OS_IOS) | |
| 15 // The first callback on iOS is received after the current background | |
| 16 // audio has faded away. | |
| 17 const int kTimerInitialIntervalSeconds = 4; | |
| 18 #else | |
| 19 const int kTimerInitialIntervalSeconds = 1; | |
| 20 #endif // defined(OS_IOS) | |
| 14 } | 21 } |
| 15 | 22 |
| 16 namespace media { | 23 namespace media { |
| 17 | 24 |
| 18 // static | 25 // static |
| 19 AudioInputController::Factory* AudioInputController::factory_ = NULL; | 26 AudioInputController::Factory* AudioInputController::factory_ = NULL; |
| 20 | 27 |
| 21 AudioInputController::AudioInputController(EventHandler* handler, | 28 AudioInputController::AudioInputController(EventHandler* handler, |
| 22 SyncWriter* sync_writer) | 29 SyncWriter* sync_writer) |
| 23 : creator_loop_(base::MessageLoopProxy::current()), | 30 : creator_loop_(base::MessageLoopProxy::current()), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 139 |
| 133 if (stream_ && !stream_->Open()) { | 140 if (stream_ && !stream_->Open()) { |
| 134 stream_->Close(); | 141 stream_->Close(); |
| 135 stream_ = NULL; | 142 stream_ = NULL; |
| 136 // TODO(satish): Define error types. | 143 // TODO(satish): Define error types. |
| 137 handler_->OnError(this, 0); | 144 handler_->OnError(this, 0); |
| 138 return; | 145 return; |
| 139 } | 146 } |
| 140 | 147 |
| 141 DCHECK(!no_data_timer_.get()); | 148 DCHECK(!no_data_timer_.get()); |
| 142 // Create the data timer which will call DoCheckForNoData() after a delay | 149 // Create the data timer which will call DoCheckForNoData(). The timer |
| 143 // of |kTimerResetInterval| seconds. The timer is started in DoRecord() | 150 // is started in DoRecord() and restarted in each DoCheckForNoData() callback. |
| 144 // and restarted in each DoCheckForNoData() callback. | 151 no_data_timer_.reset(new base::Timer(FROM_HERE, |
| 145 no_data_timer_.reset(new base::DelayTimer<AudioInputController>(FROM_HERE, | 152 base::TimeDelta::FromSeconds(kTimerInitialIntervalSeconds), |
|
scherkus (not reviewing)
2012/09/05 15:46:43
hrmmm the indentation style was incorrect prior to
Milan Broum
2012/09/05 17:12:03
Done. Your suggestion exceeded 80 chars, split it
| |
| 146 base::TimeDelta::FromSeconds(kTimerResetInterval), | 153 base::Bind(&AudioInputController::DoCheckForNoData, |
| 147 this, | 154 base::Unretained(this)), |
| 148 &AudioInputController::DoCheckForNoData)); | 155 false)); |
| 149 | 156 |
| 150 state_ = kCreated; | 157 state_ = kCreated; |
| 151 handler_->OnCreated(this); | 158 handler_->OnCreated(this); |
| 152 } | 159 } |
| 153 | 160 |
| 154 void AudioInputController::DoRecord() { | 161 void AudioInputController::DoRecord() { |
| 155 DCHECK(message_loop_->BelongsToCurrentThread()); | 162 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 156 | 163 |
| 157 if (state_ != kCreated) | 164 if (state_ != kCreated) |
| 158 return; | 165 return; |
| 159 | 166 |
| 160 { | 167 { |
| 161 base::AutoLock auto_lock(lock_); | 168 base::AutoLock auto_lock(lock_); |
| 162 state_ = kRecording; | 169 state_ = kRecording; |
| 163 } | 170 } |
| 164 | 171 |
| 165 // Start the data timer. Once |kTimerResetInterval| seconds have passed, | 172 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, |
| 166 // a callback to DoCheckForNoData() is made. | 173 // a callback to DoCheckForNoData() is made. |
| 167 no_data_timer_->Reset(); | 174 no_data_timer_->Reset(); |
| 168 | 175 |
| 169 stream_->Start(this); | 176 stream_->Start(this); |
| 170 handler_->OnRecording(this); | 177 handler_->OnRecording(this); |
| 171 } | 178 } |
| 172 | 179 |
| 173 void AudioInputController::DoClose() { | 180 void AudioInputController::DoClose() { |
| 174 DCHECK(message_loop_->BelongsToCurrentThread()); | 181 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 175 | 182 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // capture device has been removed or disabled. | 243 // capture device has been removed or disabled. |
| 237 handler_->OnError(this, 0); | 244 handler_->OnError(this, 0); |
| 238 return; | 245 return; |
| 239 } | 246 } |
| 240 | 247 |
| 241 // Mark data as non-active. The flag will be re-enabled in OnData() each | 248 // Mark data as non-active. The flag will be re-enabled in OnData() each |
| 242 // time a data packet is received. Hence, under normal conditions, the | 249 // time a data packet is received. Hence, under normal conditions, the |
| 243 // flag will only be disabled during a very short period. | 250 // flag will only be disabled during a very short period. |
| 244 SetDataIsActive(false); | 251 SetDataIsActive(false); |
| 245 | 252 |
| 246 // Restart the timer to ensure that we check the flag in one second again. | 253 // Restart the timer to ensure that we check the flag again in |
| 247 no_data_timer_->Reset(); | 254 // |kTimerResetIntervalSeconds|. |
| 255 no_data_timer_->Start(FROM_HERE, | |
|
scherkus (not reviewing)
2012/09/05 15:46:43
ditto
Milan Broum
2012/09/05 17:12:03
Done.
| |
| 256 base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), | |
| 257 base::Bind(&AudioInputController::DoCheckForNoData, | |
| 258 base::Unretained(this))); | |
| 248 } | 259 } |
| 249 | 260 |
| 250 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, | 261 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
| 251 uint32 size, uint32 hardware_delay_bytes, | 262 uint32 size, uint32 hardware_delay_bytes, |
| 252 double volume) { | 263 double volume) { |
| 253 { | 264 { |
| 254 base::AutoLock auto_lock(lock_); | 265 base::AutoLock auto_lock(lock_); |
| 255 if (state_ != kRecording) | 266 if (state_ != kRecording) |
| 256 return; | 267 return; |
| 257 } | 268 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 | 312 |
| 302 void AudioInputController::SetDataIsActive(bool enabled) { | 313 void AudioInputController::SetDataIsActive(bool enabled) { |
| 303 base::subtle::Release_Store(&data_is_active_, enabled); | 314 base::subtle::Release_Store(&data_is_active_, enabled); |
| 304 } | 315 } |
| 305 | 316 |
| 306 bool AudioInputController::GetDataIsActive() { | 317 bool AudioInputController::GetDataIsActive() { |
| 307 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 318 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
| 308 } | 319 } |
| 309 | 320 |
| 310 } // namespace media | 321 } // namespace media |
| OLD | NEW |