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

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

Issue 1357013006: Add detection for repeated audio in capturing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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 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/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 11 matching lines...) Expand all
22 22
23 namespace content { 23 namespace content {
24 24
25 namespace { 25 namespace {
26 26
27 using webrtc::AudioProcessing; 27 using webrtc::AudioProcessing;
28 using webrtc::NoiseSuppression; 28 using webrtc::NoiseSuppression;
29 29
30 const int kAudioProcessingNumberOfChannels = 1; 30 const int kAudioProcessingNumberOfChannels = 1;
31 31
32 // Minimum duration of any detectable audio repetition.
33 const int kMinLengthMs = 1;
34
35 // The following variables defines the look back time of audio repetitions that
36 // will be logged. The complexity of the detector is proportional to the number
37 // of look back times we keep track.
38 const int kMinLookbackTimeMs = 10;
39 const int kMaxLookbackTimeMs = 200;
40 const int kLookbackTimeStepMs = 10;
41
42 // Maximum frames of any input chunk of audio. Used by
43 // |MediaStreamAudioProcessor::audio_repetition_detector_|. Input longer than
44 // |kMaxFrames| won't cause any problem, and will only affect computational
45 // efficiency.
46 const size_t kMaxFrames = 480; // 10 ms * 48 kHz
47
48 // Send UMA report on an audio repetition being detected. |look_back_ms|
49 // provides the look back time of the detected repetition. This function is
50 // called back by |MediaStreamAudioProcessor::audio_repetition_detector_|.
51 void ReportRepetition(int look_back_ms) {
52 UMA_HISTOGRAM_CUSTOM_COUNTS(
53 "Media.AudioCapturerRepetition", look_back_ms,
54 kMinLookbackTimeMs, kMaxLookbackTimeMs,
55 (kMaxLookbackTimeMs - kMinLookbackTimeMs) / kLookbackTimeStepMs + 1);
56 }
57
32 AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) { 58 AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) {
33 switch (media_layout) { 59 switch (media_layout) {
34 case media::CHANNEL_LAYOUT_MONO: 60 case media::CHANNEL_LAYOUT_MONO:
35 return AudioProcessing::kMono; 61 return AudioProcessing::kMono;
36 case media::CHANNEL_LAYOUT_STEREO: 62 case media::CHANNEL_LAYOUT_STEREO:
37 return AudioProcessing::kStereo; 63 return AudioProcessing::kStereo;
38 case media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC: 64 case media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC:
39 return AudioProcessing::kStereoAndKeyboard; 65 return AudioProcessing::kStereoAndKeyboard;
40 default: 66 default:
41 NOTREACHED() << "Layout not supported: " << media_layout; 67 NOTREACHED() << "Layout not supported: " << media_layout;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 capture_thread_checker_.DetachFromThread(); 271 capture_thread_checker_.DetachFromThread();
246 render_thread_checker_.DetachFromThread(); 272 render_thread_checker_.DetachFromThread();
247 InitializeAudioProcessingModule(constraints, input_params); 273 InitializeAudioProcessingModule(constraints, input_params);
248 274
249 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); 275 aec_dump_message_filter_ = AecDumpMessageFilter::Get();
250 // In unit tests not creating a message filter, |aec_dump_message_filter_| 276 // In unit tests not creating a message filter, |aec_dump_message_filter_|
251 // will be NULL. We can just ignore that. Other unit tests and browser tests 277 // will be NULL. We can just ignore that. Other unit tests and browser tests
252 // ensure that we do get the filter when we should. 278 // ensure that we do get the filter when we should.
253 if (aec_dump_message_filter_.get()) 279 if (aec_dump_message_filter_.get())
254 aec_dump_message_filter_->AddDelegate(this); 280 aec_dump_message_filter_->AddDelegate(this);
281
282 // Create and configure |audio_repetition_detector_|.
283 std::vector<int> look_back_times;
284 for (int time = kMaxLookbackTimeMs; time >= kMinLookbackTimeMs;
285 time -= kLookbackTimeStepMs) {
286 look_back_times.push_back(time);
287 }
288 audio_repetition_detector_.reset(
289 new AudioRepetitionDetector(kMinLengthMs, kMaxFrames, look_back_times,
290 base::Bind(&ReportRepetition)));
255 } 291 }
256 292
257 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { 293 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() {
258 DCHECK(main_thread_checker_.CalledOnValidThread()); 294 DCHECK(main_thread_checker_.CalledOnValidThread());
259 Stop(); 295 Stop();
260 } 296 }
261 297
262 void MediaStreamAudioProcessor::OnCaptureFormatChanged( 298 void MediaStreamAudioProcessor::OnCaptureFormatChanged(
263 const media::AudioParameters& input_format) { 299 const media::AudioParameters& input_format) {
264 DCHECK(main_thread_checker_.CalledOnValidThread()); 300 DCHECK(main_thread_checker_.CalledOnValidThread());
(...skipping 25 matching lines...) Expand all
290 DCHECK(processed_data); 326 DCHECK(processed_data);
291 DCHECK(capture_delay); 327 DCHECK(capture_delay);
292 DCHECK(new_volume); 328 DCHECK(new_volume);
293 329
294 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); 330 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData");
295 331
296 MediaStreamAudioBus* process_bus; 332 MediaStreamAudioBus* process_bus;
297 if (!capture_fifo_->Consume(&process_bus, capture_delay)) 333 if (!capture_fifo_->Consume(&process_bus, capture_delay))
298 return false; 334 return false;
299 335
336 // Detect bit-exact repetition of audio present in the captured audio.
337 // We detect only one channel.
338 audio_repetition_detector_->Detect(process_bus->bus()->channel(0),
339 process_bus->bus()->frames(),
340 1, // number of channels
341 input_format_.sample_rate());
342
300 // Use the process bus directly if audio processing is disabled. 343 // Use the process bus directly if audio processing is disabled.
301 MediaStreamAudioBus* output_bus = process_bus; 344 MediaStreamAudioBus* output_bus = process_bus;
302 *new_volume = 0; 345 *new_volume = 0;
303 if (audio_processing_) { 346 if (audio_processing_) {
304 output_bus = output_bus_.get(); 347 output_bus = output_bus_.get();
305 *new_volume = ProcessData(process_bus->channel_ptrs(), 348 *new_volume = ProcessData(process_bus->channel_ptrs(),
306 process_bus->bus()->frames(), *capture_delay, 349 process_bus->bus()->frames(), *capture_delay,
307 volume, key_pressed, output_bus->channel_ptrs()); 350 volume, key_pressed, output_bus->channel_ptrs());
308 } 351 }
309 352
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 if (echo_information_) { 722 if (echo_information_) {
680 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); 723 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation());
681 } 724 }
682 725
683 // Return 0 if the volume hasn't been changed, and otherwise the new volume. 726 // Return 0 if the volume hasn't been changed, and otherwise the new volume.
684 return (agc->stream_analog_level() == volume) ? 727 return (agc->stream_analog_level() == volume) ?
685 0 : agc->stream_analog_level(); 728 0 : agc->stream_analog_level();
686 } 729 }
687 730
688 } // namespace content 731 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698