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

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 21183002: Adding key press detection in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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_audio_capturer.h" 5 #include "content/renderer/media/webrtc_audio_capturer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 class WebRtcAudioCapturer::TrackOwner 95 class WebRtcAudioCapturer::TrackOwner
96 : public base::RefCountedThreadSafe<WebRtcAudioCapturer::TrackOwner> { 96 : public base::RefCountedThreadSafe<WebRtcAudioCapturer::TrackOwner> {
97 public: 97 public:
98 explicit TrackOwner(WebRtcLocalAudioTrack* track) 98 explicit TrackOwner(WebRtcLocalAudioTrack* track)
99 : delegate_(track) {} 99 : delegate_(track) {}
100 100
101 void CaptureData(const int16* audio_data, 101 void CaptureData(const int16* audio_data,
102 int number_of_channels, 102 int number_of_channels,
103 int number_of_frames, 103 int number_of_frames,
104 int audio_delay_milliseconds, 104 int audio_delay_milliseconds,
105 int volume) { 105 int volume,
106 bool key_pressed) {
106 base::AutoLock lock(lock_); 107 base::AutoLock lock(lock_);
107 if (delegate_) { 108 if (delegate_) {
108 delegate_->CaptureData(audio_data, 109 delegate_->CaptureData(audio_data,
109 number_of_channels, 110 number_of_channels,
110 number_of_frames, 111 number_of_frames,
111 audio_delay_milliseconds, 112 audio_delay_milliseconds,
112 volume); 113 volume,
114 key_pressed);
113 } 115 }
114 } 116 }
115 117
116 void SetCaptureFormat(const media::AudioParameters& params) { 118 void SetCaptureFormat(const media::AudioParameters& params) {
117 base::AutoLock lock(lock_); 119 base::AutoLock lock(lock_);
118 if (delegate_) 120 if (delegate_)
119 delegate_->SetCaptureFormat(params); 121 delegate_->SetCaptureFormat(params);
120 } 122 }
121 123
122 void Reset() { 124 void Reset() {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Store the setting since SetAutomaticGainControl() can be called before 419 // Store the setting since SetAutomaticGainControl() can be called before
418 // Initialize(), in this case stored setting will be applied in Start(). 420 // Initialize(), in this case stored setting will be applied in Start().
419 agc_is_enabled_ = enable; 421 agc_is_enabled_ = enable;
420 422
421 if (source_.get()) 423 if (source_.get())
422 source_->SetAutomaticGainControl(enable); 424 source_->SetAutomaticGainControl(enable);
423 } 425 }
424 426
425 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, 427 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source,
426 int audio_delay_milliseconds, 428 int audio_delay_milliseconds,
427 double volume) { 429 double volume,
428 // This callback is driven by AudioInputDevice::AudioThreadCallback if 430 bool key_pressed) {
429 // |source_| is AudioInputDevice, otherwise it is driven by client's 431 // This callback is driven by AudioInputDevice::AudioThreadCallback if
430 // CaptureCallback. 432 // |source_| is AudioInputDevice, otherwise it is driven by client's
433 // CaptureCallback.
431 #if defined(OS_WIN) || defined(OS_MACOSX) 434 #if defined(OS_WIN) || defined(OS_MACOSX)
432 DCHECK_LE(volume, 1.0); 435 DCHECK_LE(volume, 1.0);
433 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 436 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
434 // We have a special situation on Linux where the microphone volume can be 437 // We have a special situation on Linux where the microphone volume can be
435 // "higher than maximum". The input volume slider in the sound preference 438 // "higher than maximum". The input volume slider in the sound preference
436 // allows the user to set a scaling that is higher than 100%. It means that 439 // allows the user to set a scaling that is higher than 100%. It means that
437 // even if the reported maximum levels is N, the actual microphone level can 440 // even if the reported maximum levels is N, the actual microphone level can
438 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x. 441 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x.
439 DCHECK_LE(volume, 1.6); 442 DCHECK_LE(volume, 1.6);
440 #endif 443 #endif
(...skipping 23 matching lines...) Expand all
464 // Interleave, scale, and clip input to int and store result in 467 // Interleave, scale, and clip input to int and store result in
465 // a local byte buffer. 468 // a local byte buffer.
466 audio_source->ToInterleaved(audio_source->frames(), bytes_per_sample, 469 audio_source->ToInterleaved(audio_source->frames(), bytes_per_sample,
467 buffer_ref_while_calling->buffer()); 470 buffer_ref_while_calling->buffer());
468 471
469 // Feed the data to the tracks. 472 // Feed the data to the tracks.
470 for (TrackList::const_iterator it = tracks.begin(); 473 for (TrackList::const_iterator it = tracks.begin();
471 it != tracks.end(); 474 it != tracks.end();
472 ++it) { 475 ++it) {
473 (*it)->CaptureData(buffer_ref_while_calling->buffer(), 476 (*it)->CaptureData(buffer_ref_while_calling->buffer(),
474 audio_source->channels(), audio_source->frames(), 477 audio_source->channels(),
475 audio_delay_milliseconds, volume_); 478 audio_source->frames(),
479 audio_delay_milliseconds,
480 volume,
481 key_pressed);
476 } 482 }
477 } 483 }
478 484
479 void WebRtcAudioCapturer::OnCaptureError() { 485 void WebRtcAudioCapturer::OnCaptureError() {
480 NOTIMPLEMENTED(); 486 NOTIMPLEMENTED();
481 } 487 }
482 488
483 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { 489 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const {
484 base::AutoLock auto_lock(lock_); 490 base::AutoLock auto_lock(lock_);
485 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not 491 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not
486 // been called. 492 // been called.
487 return buffer_.get() ? buffer_->params() : media::AudioParameters(); 493 return buffer_.get() ? buffer_->params() : media::AudioParameters();
488 } 494 }
489 495
490 } // namespace content 496 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.h ('k') | content/renderer/media/webrtc_audio_capturer_sink_owner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698