Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 10911067: Make initial reset period configurable for audio input no data timer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change formatting. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(
145 no_data_timer_.reset(new base::DelayTimer<AudioInputController>(FROM_HERE, 152 FROM_HERE, base::TimeDelta::FromSeconds(kTimerInitialIntervalSeconds),
146 base::TimeDelta::FromSeconds(kTimerResetInterval), 153 base::Bind(&AudioInputController::DoCheckForNoData,
147 this, 154 base::Unretained(this)), false));
148 &AudioInputController::DoCheckForNoData));
149
150 state_ = kCreated; 155 state_ = kCreated;
151 handler_->OnCreated(this); 156 handler_->OnCreated(this);
152 } 157 }
153 158
154 void AudioInputController::DoRecord() { 159 void AudioInputController::DoRecord() {
155 DCHECK(message_loop_->BelongsToCurrentThread()); 160 DCHECK(message_loop_->BelongsToCurrentThread());
156 161
157 if (state_ != kCreated) 162 if (state_ != kCreated)
158 return; 163 return;
159 164
160 { 165 {
161 base::AutoLock auto_lock(lock_); 166 base::AutoLock auto_lock(lock_);
162 state_ = kRecording; 167 state_ = kRecording;
163 } 168 }
164 169
165 // Start the data timer. Once |kTimerResetInterval| seconds have passed, 170 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed,
166 // a callback to DoCheckForNoData() is made. 171 // a callback to DoCheckForNoData() is made.
167 no_data_timer_->Reset(); 172 no_data_timer_->Reset();
168 173
169 stream_->Start(this); 174 stream_->Start(this);
170 handler_->OnRecording(this); 175 handler_->OnRecording(this);
171 } 176 }
172 177
173 void AudioInputController::DoClose() { 178 void AudioInputController::DoClose() {
174 DCHECK(message_loop_->BelongsToCurrentThread()); 179 DCHECK(message_loop_->BelongsToCurrentThread());
175 180
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // capture device has been removed or disabled. 241 // capture device has been removed or disabled.
237 handler_->OnError(this, 0); 242 handler_->OnError(this, 0);
238 return; 243 return;
239 } 244 }
240 245
241 // Mark data as non-active. The flag will be re-enabled in OnData() each 246 // 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 247 // time a data packet is received. Hence, under normal conditions, the
243 // flag will only be disabled during a very short period. 248 // flag will only be disabled during a very short period.
244 SetDataIsActive(false); 249 SetDataIsActive(false);
245 250
246 // Restart the timer to ensure that we check the flag in one second again. 251 // Restart the timer to ensure that we check the flag again in
247 no_data_timer_->Reset(); 252 // |kTimerResetIntervalSeconds|.
253 no_data_timer_->Start(
254 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds),
255 base::Bind(&AudioInputController::DoCheckForNoData,
256 base::Unretained(this)));
248 } 257 }
249 258
250 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, 259 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data,
251 uint32 size, uint32 hardware_delay_bytes, 260 uint32 size, uint32 hardware_delay_bytes,
252 double volume) { 261 double volume) {
253 { 262 {
254 base::AutoLock auto_lock(lock_); 263 base::AutoLock auto_lock(lock_);
255 if (state_ != kRecording) 264 if (state_ != kRecording)
256 return; 265 return;
257 } 266 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 310
302 void AudioInputController::SetDataIsActive(bool enabled) { 311 void AudioInputController::SetDataIsActive(bool enabled) {
303 base::subtle::Release_Store(&data_is_active_, enabled); 312 base::subtle::Release_Store(&data_is_active_, enabled);
304 } 313 }
305 314
306 bool AudioInputController::GetDataIsActive() { 315 bool AudioInputController::GetDataIsActive() {
307 return (base::subtle::Acquire_Load(&data_is_active_) != false); 316 return (base::subtle::Acquire_Load(&data_is_active_) != false);
308 } 317 }
309 318
310 } // namespace media 319 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698