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 "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 Loading... |
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) { | |
107 base::AutoLock lock(lock_); | 106 base::AutoLock lock(lock_); |
108 if (delegate_) { | 107 if (delegate_) { |
109 delegate_->CaptureData(audio_data, | 108 delegate_->CaptureData(audio_data, |
110 number_of_channels, | 109 number_of_channels, |
111 number_of_frames, | 110 number_of_frames, |
112 audio_delay_milliseconds, | 111 audio_delay_milliseconds, |
113 volume, | 112 volume); |
114 key_pressed); | |
115 } | 113 } |
116 } | 114 } |
117 | 115 |
118 void SetCaptureFormat(const media::AudioParameters& params) { | 116 void SetCaptureFormat(const media::AudioParameters& params) { |
119 base::AutoLock lock(lock_); | 117 base::AutoLock lock(lock_); |
120 if (delegate_) | 118 if (delegate_) |
121 delegate_->SetCaptureFormat(params); | 119 delegate_->SetCaptureFormat(params); |
122 } | 120 } |
123 | 121 |
124 void Reset() { | 122 void Reset() { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // Store the setting since SetAutomaticGainControl() can be called before | 417 // Store the setting since SetAutomaticGainControl() can be called before |
420 // Initialize(), in this case stored setting will be applied in Start(). | 418 // Initialize(), in this case stored setting will be applied in Start(). |
421 agc_is_enabled_ = enable; | 419 agc_is_enabled_ = enable; |
422 | 420 |
423 if (source_.get()) | 421 if (source_.get()) |
424 source_->SetAutomaticGainControl(enable); | 422 source_->SetAutomaticGainControl(enable); |
425 } | 423 } |
426 | 424 |
427 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, | 425 void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, |
428 int audio_delay_milliseconds, | 426 int audio_delay_milliseconds, |
429 double volume, | 427 double volume) { |
430 bool key_pressed) { | 428 // This callback is driven by AudioInputDevice::AudioThreadCallback if |
431 // This callback is driven by AudioInputDevice::AudioThreadCallback if | 429 // |source_| is AudioInputDevice, otherwise it is driven by client's |
432 // |source_| is AudioInputDevice, otherwise it is driven by client's | 430 // CaptureCallback. |
433 // CaptureCallback. | |
434 #if defined(OS_WIN) || defined(OS_MACOSX) | 431 #if defined(OS_WIN) || defined(OS_MACOSX) |
435 DCHECK_LE(volume, 1.0); | 432 DCHECK_LE(volume, 1.0); |
436 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | 433 #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
437 // We have a special situation on Linux where the microphone volume can be | 434 // We have a special situation on Linux where the microphone volume can be |
438 // "higher than maximum". The input volume slider in the sound preference | 435 // "higher than maximum". The input volume slider in the sound preference |
439 // allows the user to set a scaling that is higher than 100%. It means that | 436 // allows the user to set a scaling that is higher than 100%. It means that |
440 // even if the reported maximum levels is N, the actual microphone level can | 437 // even if the reported maximum levels is N, the actual microphone level can |
441 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x. | 438 // go up to 1.5x*N and that corresponds to a normalized |volume| of 1.5x. |
442 DCHECK_LE(volume, 1.6); | 439 DCHECK_LE(volume, 1.6); |
443 #endif | 440 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
467 // Interleave, scale, and clip input to int and store result in | 464 // Interleave, scale, and clip input to int and store result in |
468 // a local byte buffer. | 465 // a local byte buffer. |
469 audio_source->ToInterleaved(audio_source->frames(), bytes_per_sample, | 466 audio_source->ToInterleaved(audio_source->frames(), bytes_per_sample, |
470 buffer_ref_while_calling->buffer()); | 467 buffer_ref_while_calling->buffer()); |
471 | 468 |
472 // Feed the data to the tracks. | 469 // Feed the data to the tracks. |
473 for (TrackList::const_iterator it = tracks.begin(); | 470 for (TrackList::const_iterator it = tracks.begin(); |
474 it != tracks.end(); | 471 it != tracks.end(); |
475 ++it) { | 472 ++it) { |
476 (*it)->CaptureData(buffer_ref_while_calling->buffer(), | 473 (*it)->CaptureData(buffer_ref_while_calling->buffer(), |
477 audio_source->channels(), | 474 audio_source->channels(), audio_source->frames(), |
478 audio_source->frames(), | 475 audio_delay_milliseconds, volume_); |
479 audio_delay_milliseconds, | |
480 volume, | |
481 key_pressed); | |
482 } | 476 } |
483 } | 477 } |
484 | 478 |
485 void WebRtcAudioCapturer::OnCaptureError() { | 479 void WebRtcAudioCapturer::OnCaptureError() { |
486 NOTIMPLEMENTED(); | 480 NOTIMPLEMENTED(); |
487 } | 481 } |
488 | 482 |
489 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { | 483 media::AudioParameters WebRtcAudioCapturer::audio_parameters() const { |
490 base::AutoLock auto_lock(lock_); | 484 base::AutoLock auto_lock(lock_); |
491 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not | 485 // |buffer_| can be NULL when SetCapturerSource() or Initialize() has not |
492 // been called. | 486 // been called. |
493 return buffer_.get() ? buffer_->params() : media::AudioParameters(); | 487 return buffer_.get() ? buffer_->params() : media::AudioParameters(); |
494 } | 488 } |
495 | 489 |
496 } // namespace content | 490 } // namespace content |
OLD | NEW |