Chromium Code Reviews| Index: content/renderer/media/webrtc_audio_capturer.cc |
| diff --git a/content/renderer/media/webrtc_audio_capturer.cc b/content/renderer/media/webrtc_audio_capturer.cc |
| index c59695a72f6a97f7651004220eabdc9e801a3061..8aed1cbf9c0ccbcb4cd1892e4ce9da1572ef4d72 100644 |
| --- a/content/renderer/media/webrtc_audio_capturer.cc |
| +++ b/content/renderer/media/webrtc_audio_capturer.cc |
| @@ -14,6 +14,7 @@ |
| #include "content/renderer/media/media_stream_audio_processor.h" |
| #include "content/renderer/media/media_stream_audio_processor_options.h" |
| #include "content/renderer/media/media_stream_audio_source.h" |
| +#include "content/renderer/media/media_stream_constraints_util.h" |
| #include "content/renderer/media/webrtc_audio_device_impl.h" |
| #include "content/renderer/media/webrtc_local_audio_track.h" |
| #include "content/renderer/media/webrtc_logging.h" |
| @@ -23,6 +24,8 @@ namespace content { |
| namespace { |
| +const char kAudioBufferSizeMs[] = "audioBufferSizeMs"; |
| + |
| // Method to check if any of the data in |audio_source| has energy. |
| bool HasDataEnergy(const media::AudioBus& audio_source) { |
| for (int ch = 0; ch < audio_source.channels(); ++ch) { |
| @@ -89,7 +92,7 @@ class WebRtcAudioCapturer::TrackOwner |
| // Wrapper which allows to use std::find_if() when adding and removing |
| // sinks to/from the list. |
| struct TrackWrapper { |
| - TrackWrapper(WebRtcLocalAudioTrack* track) : track_(track) {} |
| + explicit TrackWrapper(WebRtcLocalAudioTrack* track) : track_(track) {} |
|
Charlie
2015/05/06 23:47:44
Fixing linter error.
|
| bool operator()( |
| const scoped_refptr<WebRtcAudioCapturer::TrackOwner>& owner) const { |
| return owner->IsEqual(track_); |
| @@ -188,21 +191,30 @@ bool WebRtcAudioCapturer::Initialize() { |
| return false; |
| } |
| + const int& sample_rate = device_info_.device.input.sample_rate; |
| DVLOG(1) << "Audio input hardware sample rate: " |
| << device_info_.device.input.sample_rate; |
| media::AudioSampleRate asr; |
| - if (media::ToAudioSampleRate(device_info_.device.input.sample_rate, &asr)) { |
| + if (media::ToAudioSampleRate(sample_rate, &asr)) { |
| UMA_HISTOGRAM_ENUMERATION( |
| "WebRTC.AudioInputSampleRate", asr, media::kAudioSampleRateMax + 1); |
| } else { |
| - UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected", |
| - device_info_.device.input.sample_rate); |
| + UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected", sample_rate); |
| } |
| + int buffer_size_ms = 0; |
| + GetOptionalConstraintValueAsInteger( |
| + constraints_, kAudioBufferSizeMs, &buffer_size_ms); |
| + int buffer_size = sample_rate * buffer_size_ms / 1000; |
| + if (buffer_size > 0) |
| + DVLOG(1) << "Custom audio buffer size: " << buffer_size; |
| + |
| // Create and configure the default audio capturing source. |
| SetCapturerSourceInternal( |
| - AudioDeviceFactory::NewInputDevice(render_frame_id_), channel_layout, |
| - static_cast<float>(device_info_.device.input.sample_rate)); |
| + AudioDeviceFactory::NewInputDevice(render_frame_id_), |
| + channel_layout, |
| + sample_rate, |
| + buffer_size); |
| // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware |
| // information from the capturer. |
| @@ -287,7 +299,8 @@ void WebRtcAudioCapturer::RemoveTrack(WebRtcLocalAudioTrack* track) { |
| void WebRtcAudioCapturer::SetCapturerSourceInternal( |
| const scoped_refptr<media::AudioCapturerSource>& source, |
| media::ChannelLayout channel_layout, |
| - float sample_rate) { |
| + int sample_rate, |
| + int buffer_size) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," |
| << "sample_rate=" << sample_rate << ")"; |
| @@ -313,10 +326,13 @@ void WebRtcAudioCapturer::SetCapturerSourceInternal( |
| // The idea is to get rid of any dependency of the microphone parameters |
| // which would normally be used by default. |
| // bits_per_sample is always 16 for now. |
| - int buffer_size = GetBufferSize(sample_rate); |
| + if (!buffer_size) |
| + buffer_size = GetBufferSize(sample_rate); |
| media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| - channel_layout, sample_rate, |
| - 16, buffer_size, |
| + channel_layout, |
| + sample_rate, |
| + 16, |
| + buffer_size, |
| device_info_.device.input.effects); |
| { |
| @@ -365,7 +381,8 @@ void WebRtcAudioCapturer::EnablePeerConnectionMode() { |
| // WebRtc native buffer size. |
| SetCapturerSourceInternal(AudioDeviceFactory::NewInputDevice(render_frame_id), |
| input_params.channel_layout(), |
| - static_cast<float>(input_params.sample_rate())); |
| + input_params.sample_rate(), |
| + 0); |
| } |
| void WebRtcAudioCapturer::Start() { |
| @@ -588,8 +605,10 @@ void WebRtcAudioCapturer::SetCapturerSource( |
| const scoped_refptr<media::AudioCapturerSource>& source, |
| media::AudioParameters params) { |
| // Create a new audio stream as source which uses the new source. |
| - SetCapturerSourceInternal(source, params.channel_layout(), |
| - static_cast<float>(params.sample_rate())); |
| + SetCapturerSourceInternal(source, |
| + params.channel_layout(), |
| + params.sample_rate(), |
| + 0); |
| } |
| } // namespace content |