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

Side by Side Diff: content/renderer/media/webrtc/processed_local_audio_source.cc

Issue 2888383002: Stop source and fire MediaStreamTrack ended event if missing audio input callbacks are detected. (Closed)
Patch Set: Created 3 years, 7 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
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 "content/renderer/media/webrtc/processed_local_audio_source.h" 5 #include "content/renderer/media/webrtc/processed_local_audio_source.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/renderer/media/audio_device_factory.h" 10 #include "content/renderer/media/audio_device_factory.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 new_source->SetAutomaticGainControl(true); 194 new_source->SetAutomaticGainControl(true);
195 { 195 {
196 base::AutoLock auto_lock(source_lock_); 196 base::AutoLock auto_lock(source_lock_);
197 source_ = std::move(new_source); 197 source_ = std::move(new_source);
198 } 198 }
199 source_->Start(); 199 source_->Start();
200 200
201 // Register this source with the WebRtcAudioDeviceImpl. 201 // Register this source with the WebRtcAudioDeviceImpl.
202 rtc_audio_device->AddAudioCapturer(this); 202 rtc_audio_device->AddAudioCapturer(this);
203 203
204 // Start detecting no callbacks.
205 base::subtle::Release_Store(&input_callback_is_active_, false);
206 last_callback_time_ = base::TimeTicks::Now();
207 check_alive_timer_.Start(
208 FROM_HERE, base::TimeDelta::FromSeconds(5),
209 this, &ProcessedLocalAudioSource::CheckIfInputStreamIsAlive);
210 DCHECK(check_alive_timer_.IsRunning());
211
204 return true; 212 return true;
205 } 213 }
206 214
207 void ProcessedLocalAudioSource::EnsureSourceIsStopped() { 215 void ProcessedLocalAudioSource::EnsureSourceIsStopped() {
208 DCHECK(thread_checker_.CalledOnValidThread()); 216 DCHECK(thread_checker_.CalledOnValidThread());
209 217
218 check_alive_timer_.Stop();
219 DCHECK(!check_alive_timer_.IsRunning());
220
210 scoped_refptr<media::AudioCapturerSource> source_to_stop; 221 scoped_refptr<media::AudioCapturerSource> source_to_stop;
211 { 222 {
212 base::AutoLock auto_lock(source_lock_); 223 base::AutoLock auto_lock(source_lock_);
213 if (!source_) 224 if (!source_)
214 return; 225 return;
215 source_to_stop = std::move(source_); 226 source_to_stop = std::move(source_);
216 } 227 }
217 228
218 if (WebRtcAudioDeviceImpl* rtc_audio_device = 229 if (WebRtcAudioDeviceImpl* rtc_audio_device =
219 pc_factory_->GetWebRtcAudioDevice()) { 230 pc_factory_->GetWebRtcAudioDevice()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 271 }
261 272
262 void ProcessedLocalAudioSource::OnCaptureStarted() { 273 void ProcessedLocalAudioSource::OnCaptureStarted() {
263 started_callback_.Run(this, MEDIA_DEVICE_OK, ""); 274 started_callback_.Run(this, MEDIA_DEVICE_OK, "");
264 } 275 }
265 276
266 void ProcessedLocalAudioSource::Capture(const media::AudioBus* audio_bus, 277 void ProcessedLocalAudioSource::Capture(const media::AudioBus* audio_bus,
267 int audio_delay_milliseconds, 278 int audio_delay_milliseconds,
268 double volume, 279 double volume,
269 bool key_pressed) { 280 bool key_pressed) {
281 base::subtle::Release_Store(&input_callback_is_active_, true);
ossu-chromium 2017/05/18 13:38:54 Perhaps just store last_callback_time_ atomically?
Henrik Grunell 2017/05/19 06:00:00 Yeah, this is going away. The CL is not ready for
282 // TODO: Post task.
283 last_callback_time_ = base::TimeTicks::Now();
284
270 #if defined(OS_WIN) || defined(OS_MACOSX) 285 #if defined(OS_WIN) || defined(OS_MACOSX)
271 DCHECK_LE(volume, 1.0); 286 DCHECK_LE(volume, 1.0);
272 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_OPENBSD) 287 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_OPENBSD)
273 // We have a special situation on Linux where the microphone volume can be 288 // We have a special situation on Linux where the microphone volume can be
274 // "higher than maximum". The input volume slider in the sound preference 289 // "higher than maximum". The input volume slider in the sound preference
275 // allows the user to set a scaling that is higher than 100%. It means that 290 // allows the user to set a scaling that is higher than 100%. It means that
276 // even if the reported maximum levels is N, the actual microphone level can 291 // even if the reported maximum levels is N, the actual microphone level can
277 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x. 292 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x.
278 DCHECK_LE(volume, 1.6); 293 DCHECK_LE(volume, 1.6);
279 #endif 294 #endif
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return hardware_buffer_size; 381 return hardware_buffer_size;
367 382
368 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a 383 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a
369 // fall-back. 384 // fall-back.
370 // 385 //
371 // TODO(miu): Identify where/why the buffer size might be missing, fix the 386 // TODO(miu): Identify where/why the buffer size might be missing, fix the
372 // code, and then require it here. http://crbug.com/638081 387 // code, and then require it here. http://crbug.com/638081
373 return (sample_rate / 100); 388 return (sample_rate / 100);
374 } 389 }
375 390
391 void ProcessedLocalAudioSource::CheckIfInputStreamIsAlive() {
392 DCHECK(thread_checker_.CalledOnValidThread());
393
394 // bool active = base::subtle::Acquire_Load(&input_callback_is_active_);
395 base::TimeDelta time_since_last_callback =
396 base::TimeTicks::Now() - last_callback_time_;
397 if (time_since_last_callback > base::TimeDelta::FromSeconds(5)) {
398 // if (!active) {
399 LOG(ERROR) << "********** Detected missing callbacks. Stopping.";
400 StopSourceOnError("Detected missing callbacks.");
401 }
402 }
403
376 } // namespace content 404 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc/processed_local_audio_source.h ('k') | media/audio/pulse/pulse_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698