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

Unified Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 1130063002: Allowing a custom audio buffer size in WebRtcAudioCapturer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
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..2f8b52ddab7963f875266a8cefa36a06851d2c52 100644
--- a/content/renderer/media/webrtc_audio_capturer.cc
+++ b/content/renderer/media/webrtc_audio_capturer.cc
@@ -9,11 +9,13 @@
#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "cc/base/math_util.h"
#include "content/child/child_process.h"
#include "content/renderer/media/audio_device_factory.h"
#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 +25,12 @@ namespace content {
namespace {
+const char kAudioLatency[] = "latency";
henrika (OOO until Aug 14) 2015/05/14 15:19:51 Is it clear from this name that this is for the ca
Charlie 2015/05/14 16:46:10 The JS will look like this: navigator.webkitGetUs
+const double kMinAudioLatency = 0;
henrika (OOO until Aug 14) 2015/05/14 15:19:51 Add unit.
tommi (sloooow) - chröme 2015/05/14 16:29:26 It's not clear if this is a buffer size or time va
Charlie 2015/05/14 17:30:52 Done.
+const double kMaxAudioLatency = 60;
+
+const int kDontUseBufferSizeParameter = 0;
henrika (OOO until Aug 14) 2015/05/14 15:19:51 Is it used?
tommi (sloooow) - chröme 2015/05/14 16:29:26 From the name, it sounds like this should be a boo
Charlie 2015/05/14 16:46:10 I think Henrik was suggesting that we "tag" the ze
Charlie 2015/05/14 17:30:52 Done.
+
// 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 +97,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) {}
bool operator()(
const scoped_refptr<WebRtcAudioCapturer::TrackOwner>& owner) const {
return owner->IsEqual(track_);
@@ -188,21 +196,32 @@ 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)) {
tommi (sloooow) - chröme 2015/05/14 16:29:26 nit: to keep the change simple, can you revert the
Charlie 2015/05/14 17:30:52 Done.
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);
}
+ double buffer_size_seconds = 0;
henrika (OOO until Aug 14) 2015/05/14 15:19:51 is it really in seconds!? Should it not be in mill
Charlie 2015/05/14 16:46:10 I can drop the max to 10 seconds if you want. I do
+ GetConstraintValueAsDouble(
+ constraints_, kAudioLatency, &buffer_size_seconds);
tommi (sloooow) - chröme 2015/05/14 16:29:26 seconds doesn't feel right. also I think you need
Charlie 2015/05/14 16:46:10 On the w3c thread it was pointed out that millisec
Charlie 2015/05/14 17:30:52 Fixed to ignore out-of-range values.
+ buffer_size_seconds = cc::MathUtil::ClampToRange(
tommi (sloooow) - chröme 2015/05/14 16:29:25 with the above, I think that would also remove the
Charlie 2015/05/14 16:46:10 Well, we still need to clamp the value if the user
+ buffer_size_seconds, kMinAudioLatency, kMaxAudioLatency);
+ int buffer_size = sample_rate * buffer_size_seconds;
+ if (buffer_size > 0)
henrika (OOO until Aug 14) 2015/05/14 15:19:51 > kDontUse...
Charlie 2015/05/14 17:30:52 Done.
+ 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 +306,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 +333,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 == kDontUseBufferSizeParameter)
henrika (OOO until Aug 14) 2015/05/14 15:19:51 Make a clear comment about what happens here and w
Charlie 2015/05/14 17:30:53 Done.
+ 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 +388,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 +612,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

Powered by Google App Engine
This is Rietveld 408576698