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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 stream_->Close(); | 141 stream_->Close(); |
142 stream_ = NULL; | 142 stream_ = NULL; |
143 // TODO(satish): Define error types. | 143 // TODO(satish): Define error types. |
144 handler_->OnError(this, 0); | 144 handler_->OnError(this, 0); |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 DCHECK(!no_data_timer_.get()); | 148 DCHECK(!no_data_timer_.get()); |
149 // Create the data timer which will call DoCheckForNoData(). The timer | 149 // Create the data timer which will call DoCheckForNoData(). The timer |
150 // is started in DoRecord() and restarted in each DoCheckForNoData() callback. | 150 // is started in DoRecord() and restarted in each DoCheckForNoData() callback. |
151 no_data_timer_.reset(new base::Timer( | 151 if (params.format() != AudioParameters::AUDIO_MIRROR_BROWSER) { |
Alpha Left Google
2012/11/28 01:04:47
Why special case for audio mirroring? You can give
justinlin
2012/11/28 14:30:31
In a previous iteration, this was causing crashes
| |
152 FROM_HERE, base::TimeDelta::FromSeconds(kTimerInitialIntervalSeconds), | 152 no_data_timer_.reset(new base::Timer( |
153 base::Bind(&AudioInputController::DoCheckForNoData, | 153 FROM_HERE, base::TimeDelta::FromSeconds(kTimerInitialIntervalSeconds), |
154 base::Unretained(this)), false)); | 154 base::Bind(&AudioInputController::DoCheckForNoData, |
155 base::Unretained(this)), false)); | |
156 } | |
155 state_ = kCreated; | 157 state_ = kCreated; |
156 handler_->OnCreated(this); | 158 handler_->OnCreated(this); |
157 } | 159 } |
158 | 160 |
159 void AudioInputController::DoRecord() { | 161 void AudioInputController::DoRecord() { |
160 DCHECK(message_loop_->BelongsToCurrentThread()); | 162 DCHECK(message_loop_->BelongsToCurrentThread()); |
161 | 163 |
162 if (state_ != kCreated) | 164 if (state_ != kCreated) |
163 return; | 165 return; |
164 | 166 |
165 { | 167 { |
166 base::AutoLock auto_lock(lock_); | 168 base::AutoLock auto_lock(lock_); |
167 state_ = kRecording; | 169 state_ = kRecording; |
168 } | 170 } |
169 | 171 |
170 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, | 172 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, |
171 // a callback to DoCheckForNoData() is made. | 173 // a callback to DoCheckForNoData() is made. |
172 no_data_timer_->Reset(); | 174 if (no_data_timer_.get()) |
175 no_data_timer_->Reset(); | |
173 | 176 |
174 stream_->Start(this); | 177 stream_->Start(this); |
175 handler_->OnRecording(this); | 178 handler_->OnRecording(this); |
176 } | 179 } |
177 | 180 |
178 void AudioInputController::DoClose() { | 181 void AudioInputController::DoClose() { |
179 DCHECK(message_loop_->BelongsToCurrentThread()); | 182 DCHECK(message_loop_->BelongsToCurrentThread()); |
180 | 183 |
181 // Delete the timer on the same thread that created it. | 184 // Delete the timer on the same thread that created it. |
182 no_data_timer_.reset(); | 185 no_data_timer_.reset(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 return; | 246 return; |
244 } | 247 } |
245 | 248 |
246 // Mark data as non-active. The flag will be re-enabled in OnData() each | 249 // Mark data as non-active. The flag will be re-enabled in OnData() each |
247 // time a data packet is received. Hence, under normal conditions, the | 250 // time a data packet is received. Hence, under normal conditions, the |
248 // flag will only be disabled during a very short period. | 251 // flag will only be disabled during a very short period. |
249 SetDataIsActive(false); | 252 SetDataIsActive(false); |
250 | 253 |
251 // Restart the timer to ensure that we check the flag again in | 254 // Restart the timer to ensure that we check the flag again in |
252 // |kTimerResetIntervalSeconds|. | 255 // |kTimerResetIntervalSeconds|. |
253 no_data_timer_->Start( | 256 if (no_data_timer_.get()) |
254 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), | 257 no_data_timer_->Start( |
255 base::Bind(&AudioInputController::DoCheckForNoData, | 258 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), |
256 base::Unretained(this))); | 259 base::Bind(&AudioInputController::DoCheckForNoData, |
260 base::Unretained(this))); | |
257 } | 261 } |
258 | 262 |
259 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, | 263 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
260 uint32 size, uint32 hardware_delay_bytes, | 264 uint32 size, uint32 hardware_delay_bytes, |
261 double volume) { | 265 double volume) { |
262 { | 266 { |
263 base::AutoLock auto_lock(lock_); | 267 base::AutoLock auto_lock(lock_); |
264 if (state_ != kRecording) | 268 if (state_ != kRecording) |
265 return; | 269 return; |
266 } | 270 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 314 |
311 void AudioInputController::SetDataIsActive(bool enabled) { | 315 void AudioInputController::SetDataIsActive(bool enabled) { |
312 base::subtle::Release_Store(&data_is_active_, enabled); | 316 base::subtle::Release_Store(&data_is_active_, enabled); |
313 } | 317 } |
314 | 318 |
315 bool AudioInputController::GetDataIsActive() { | 319 bool AudioInputController::GetDataIsActive() { |
316 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 320 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
317 } | 321 } |
318 | 322 |
319 } // namespace media | 323 } // namespace media |
OLD | NEW |