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

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

Issue 200293002: added uma stats to check the usage of media stream audio track audio processing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: added AUDIO_PROCESSING_IN_WEBRTC Created 6 years, 9 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media_stream_audio_processor.h" 5 #include "content/renderer/media/media_stream_audio_processor.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
10 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
11 #include "content/renderer/media/media_stream_audio_processor_options.h" 12 #include "content/renderer/media/media_stream_audio_processor_options.h"
12 #include "content/renderer/media/rtc_media_constraints.h" 13 #include "content/renderer/media/rtc_media_constraints.h"
13 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
14 #include "media/base/audio_converter.h" 15 #include "media/base/audio_converter.h"
15 #include "media/base/audio_fifo.h" 16 #include "media/base/audio_fifo.h"
16 #include "media/base/channel_layout.h" 17 #include "media/base/channel_layout.h"
17 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 18 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
18 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" 19 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
19 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" 20 #include "third_party/webrtc/modules/audio_processing/typing_detection.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 namespace { 24 namespace {
24 25
25 using webrtc::AudioProcessing; 26 using webrtc::AudioProcessing;
26 using webrtc::MediaConstraintsInterface; 27 using webrtc::MediaConstraintsInterface;
27 28
28 #if defined(OS_ANDROID) 29 #if defined(OS_ANDROID)
29 const int kAudioProcessingSampleRate = 16000; 30 const int kAudioProcessingSampleRate = 16000;
30 #else 31 #else
31 const int kAudioProcessingSampleRate = 32000; 32 const int kAudioProcessingSampleRate = 32000;
32 #endif 33 #endif
33 const int kAudioProcessingNumberOfChannel = 1; 34 const int kAudioProcessingNumberOfChannel = 1;
tommi (sloooow) - chröme 2014/03/17 16:00:39 nit: kAudioProcessingNumberOfChannels (plural) I
no longer working on chromium 2014/03/19 12:50:11 Done.
34 35
35 const int kMaxNumberOfBuffersInFifo = 2; 36 const int kMaxNumberOfBuffersInFifo = 2;
36 37
38 enum AudioTrackProcessingStates {
Alexei Svitkine (slow) 2014/03/17 22:15:50 Nit: Add a comment that this is used for an UMA hi
no longer working on chromium 2014/03/19 12:50:11 Done.
39 AUDIO_PROCESSING_ENABLED = 0,
40 AUDIO_PROCESSING_DISABLED,
41 AUDIO_PROCESSING_IN_WEBRTC,
42 AUDIO_PROCESSING_MAX
43 };
44
37 } // namespace 45 } // namespace
38 46
39 class MediaStreamAudioProcessor::MediaStreamAudioConverter 47 class MediaStreamAudioProcessor::MediaStreamAudioConverter
40 : public media::AudioConverter::InputCallback { 48 : public media::AudioConverter::InputCallback {
41 public: 49 public:
42 MediaStreamAudioConverter(const media::AudioParameters& source_params, 50 MediaStreamAudioConverter(const media::AudioParameters& source_params,
43 const media::AudioParameters& sink_params) 51 const media::AudioParameters& sink_params)
44 : source_params_(source_params), 52 : source_params_(source_params),
45 sink_params_(sink_params), 53 sink_params_(sink_params),
46 audio_converter_(source_params, sink_params_, false) { 54 audio_converter_(source_params, sink_params_, false) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { 266 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) {
259 stats->typing_noise_detected = 267 stats->typing_noise_detected =
260 (base::subtle::Acquire_Load(&typing_detected_) != false); 268 (base::subtle::Acquire_Load(&typing_detected_) != false);
261 GetAecStats(audio_processing_.get(), stats); 269 GetAecStats(audio_processing_.get(), stats);
262 } 270 }
263 271
264 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( 272 void MediaStreamAudioProcessor::InitializeAudioProcessingModule(
265 const blink::WebMediaConstraints& constraints, int effects, 273 const blink::WebMediaConstraints& constraints, int effects,
266 MediaStreamType type) { 274 MediaStreamType type) {
267 DCHECK(!audio_processing_); 275 DCHECK(!audio_processing_);
268 if (!IsAudioTrackProcessingEnabled()) 276 if (!IsAudioTrackProcessingEnabled()) {
277 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates",
278 AUDIO_PROCESSING_IN_WEBRTC, AUDIO_PROCESSING_MAX);
269 return; 279 return;
280 }
270 281
271 RTCMediaConstraints native_constraints(constraints); 282 RTCMediaConstraints native_constraints(constraints);
272 283
273 // Only apply the fixed constraints for gUM of MEDIA_DEVICE_AUDIO_CAPTURE. 284 // Only apply the fixed constraints for gUM of MEDIA_DEVICE_AUDIO_CAPTURE.
274 DCHECK(IsAudioMediaType(type)); 285 DCHECK(IsAudioMediaType(type));
275 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) 286 if (type == MEDIA_DEVICE_AUDIO_CAPTURE)
276 ApplyFixedAudioConstraints(&native_constraints); 287 ApplyFixedAudioConstraints(&native_constraints);
277 288
278 if (effects & media::AudioParameters::ECHO_CANCELLER) { 289 if (effects & media::AudioParameters::ECHO_CANCELLER) {
279 // If platform echo canceller is enabled, disable the software AEC. 290 // If platform echo canceller is enabled, disable the software AEC.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 const bool enable_high_pass_filter = GetPropertyFromConstraints( 323 const bool enable_high_pass_filter = GetPropertyFromConstraints(
313 &native_constraints, MediaConstraintsInterface::kHighpassFilter); 324 &native_constraints, MediaConstraintsInterface::kHighpassFilter);
314 325
315 audio_mirroring_ = GetPropertyFromConstraints( 326 audio_mirroring_ = GetPropertyFromConstraints(
316 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); 327 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring);
317 328
318 // Return immediately if no audio processing component is enabled. 329 // Return immediately if no audio processing component is enabled.
319 if (!enable_aec && !enable_experimental_aec && !enable_ns && 330 if (!enable_aec && !enable_experimental_aec && !enable_ns &&
320 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && 331 !enable_high_pass_filter && !enable_typing_detection && !enable_agc &&
321 !enable_experimental_ns) { 332 !enable_experimental_ns) {
333 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates",
334 AUDIO_PROCESSING_DISABLED, AUDIO_PROCESSING_MAX);
322 return; 335 return;
323 } 336 }
324 337
325 // Create and configure the webrtc::AudioProcessing. 338 // Create and configure the webrtc::AudioProcessing.
326 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); 339 audio_processing_.reset(webrtc::AudioProcessing::Create(0));
327 340
328 // Enable the audio processing components. 341 // Enable the audio processing components.
329 if (enable_aec) { 342 if (enable_aec) {
330 EnableEchoCancellation(audio_processing_.get()); 343 EnableEchoCancellation(audio_processing_.get());
331 if (enable_experimental_aec) 344 if (enable_experimental_aec)
(...skipping 22 matching lines...) Expand all
354 if (enable_agc) 367 if (enable_agc)
355 EnableAutomaticGainControl(audio_processing_.get()); 368 EnableAutomaticGainControl(audio_processing_.get());
356 369
357 // Configure the audio format the audio processing is running on. This 370 // Configure the audio format the audio processing is running on. This
358 // has to be done after all the needed components are enabled. 371 // has to be done after all the needed components are enabled.
359 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), 372 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate),
360 0); 373 0);
361 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, 374 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel,
362 kAudioProcessingNumberOfChannel), 375 kAudioProcessingNumberOfChannel),
363 0); 376 0);
377
378 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates",
Alexei Svitkine (slow) 2014/03/17 22:15:50 Nit: Can you make a function in the anon namespace
no longer working on chromium 2014/03/19 12:50:11 Done.
379 AUDIO_PROCESSING_ENABLED, AUDIO_PROCESSING_MAX);
364 } 380 }
365 381
366 void MediaStreamAudioProcessor::InitializeCaptureConverter( 382 void MediaStreamAudioProcessor::InitializeCaptureConverter(
367 const media::AudioParameters& source_params) { 383 const media::AudioParameters& source_params) {
368 DCHECK(main_thread_checker_.CalledOnValidThread()); 384 DCHECK(main_thread_checker_.CalledOnValidThread());
369 DCHECK(source_params.IsValid()); 385 DCHECK(source_params.IsValid());
370 386
371 // Create and initialize audio converter for the source data. 387 // Create and initialize audio converter for the source data.
372 // When the webrtc AudioProcessing is enabled, the sink format of the 388 // When the webrtc AudioProcessing is enabled, the sink format of the
373 // converter will be the same as the post-processed data format, which is 389 // converter will be the same as the post-processed data format, which is
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 505 }
490 506
491 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() const { 507 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() const {
492 const std::string group_name = 508 const std::string group_name =
493 base::FieldTrialList::FindFullName("MediaStreamAudioTrackProcessing"); 509 base::FieldTrialList::FindFullName("MediaStreamAudioTrackProcessing");
494 return group_name == "Enabled" || CommandLine::ForCurrentProcess()->HasSwitch( 510 return group_name == "Enabled" || CommandLine::ForCurrentProcess()->HasSwitch(
495 switches::kEnableAudioTrackProcessing); 511 switches::kEnableAudioTrackProcessing);
496 } 512 }
497 513
498 } // namespace content 514 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698