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

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

Issue 11298006: Browser-wide audio mirroring for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adress comments Created 8 years 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 | Annotate | Revision Log
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
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
no longer working on chromium 2012/11/26 22:20:07 nit, add a {}
justinlin 2012/11/27 22:26:12 Done.
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));
155 state_ = kCreated; 156 state_ = kCreated;
156 handler_->OnCreated(this); 157 handler_->OnCreated(this);
157 } 158 }
158 159
159 void AudioInputController::DoRecord() { 160 void AudioInputController::DoRecord() {
160 DCHECK(message_loop_->BelongsToCurrentThread()); 161 DCHECK(message_loop_->BelongsToCurrentThread());
161 162
162 if (state_ != kCreated) 163 if (state_ != kCreated)
163 return; 164 return;
164 165
165 { 166 {
166 base::AutoLock auto_lock(lock_); 167 base::AutoLock auto_lock(lock_);
167 state_ = kRecording; 168 state_ = kRecording;
168 } 169 }
169 170
170 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, 171 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed,
171 // a callback to DoCheckForNoData() is made. 172 // a callback to DoCheckForNoData() is made.
172 no_data_timer_->Reset(); 173 if (no_data_timer_.get())
174 no_data_timer_->Reset();
173 175
174 stream_->Start(this); 176 stream_->Start(this);
175 handler_->OnRecording(this); 177 handler_->OnRecording(this);
176 } 178 }
177 179
178 void AudioInputController::DoClose() { 180 void AudioInputController::DoClose() {
179 DCHECK(message_loop_->BelongsToCurrentThread()); 181 DCHECK(message_loop_->BelongsToCurrentThread());
180 182
181 // Delete the timer on the same thread that created it. 183 // Delete the timer on the same thread that created it.
182 no_data_timer_.reset(); 184 no_data_timer_.reset();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return; 245 return;
244 } 246 }
245 247
246 // 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
247 // time a data packet is received. Hence, under normal conditions, the 249 // time a data packet is received. Hence, under normal conditions, the
248 // flag will only be disabled during a very short period. 250 // flag will only be disabled during a very short period.
249 SetDataIsActive(false); 251 SetDataIsActive(false);
250 252
251 // Restart the timer to ensure that we check the flag again in 253 // Restart the timer to ensure that we check the flag again in
252 // |kTimerResetIntervalSeconds|. 254 // |kTimerResetIntervalSeconds|.
253 no_data_timer_->Start( 255 if (no_data_timer_.get())
254 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), 256 no_data_timer_->Start(
255 base::Bind(&AudioInputController::DoCheckForNoData, 257 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds),
256 base::Unretained(this))); 258 base::Bind(&AudioInputController::DoCheckForNoData,
259 base::Unretained(this)));
257 } 260 }
258 261
259 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, 262 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data,
260 uint32 size, uint32 hardware_delay_bytes, 263 uint32 size, uint32 hardware_delay_bytes,
261 double volume) { 264 double volume) {
262 { 265 {
263 base::AutoLock auto_lock(lock_); 266 base::AutoLock auto_lock(lock_);
264 if (state_ != kRecording) 267 if (state_ != kRecording)
265 return; 268 return;
266 } 269 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 313
311 void AudioInputController::SetDataIsActive(bool enabled) { 314 void AudioInputController::SetDataIsActive(bool enabled) {
312 base::subtle::Release_Store(&data_is_active_, enabled); 315 base::subtle::Release_Store(&data_is_active_, enabled);
313 } 316 }
314 317
315 bool AudioInputController::GetDataIsActive() { 318 bool AudioInputController::GetDataIsActive() {
316 return (base::subtle::Acquire_Load(&data_is_active_) != false); 319 return (base::subtle::Acquire_Load(&data_is_active_) != false);
317 } 320 }
318 321
319 } // namespace media 322 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698