Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 a repetition. | |
|
Henrik Grunell
2015/10/20 08:50:16
Put these in the AudioRepetitionReporter class.
minyue
2015/10/23 12:05:23
The class is not present any longer. We may put th
| |
| 33 const int kMinLengthMs = 1; | |
| 34 | |
| 35 // The following variables defines the look back time of repetitions that will | |
| 36 // be logged. The complexity of the detector is proportional to the number of | |
| 37 // 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. Input longer than |kMaxFrames| | |
| 43 // won't cause any problem, and will only affect computational efficiency. | |
| 44 const size_t kMaxFrames = 480; // 10 ms * 48 kHz | |
| 45 | |
| 32 AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) { | 46 AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) { |
| 33 switch (media_layout) { | 47 switch (media_layout) { |
| 34 case media::CHANNEL_LAYOUT_MONO: | 48 case media::CHANNEL_LAYOUT_MONO: |
| 35 return AudioProcessing::kMono; | 49 return AudioProcessing::kMono; |
| 36 case media::CHANNEL_LAYOUT_STEREO: | 50 case media::CHANNEL_LAYOUT_STEREO: |
| 37 return AudioProcessing::kStereo; | 51 return AudioProcessing::kStereo; |
| 38 case media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC: | 52 case media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC: |
| 39 return AudioProcessing::kStereoAndKeyboard; | 53 return AudioProcessing::kStereoAndKeyboard; |
| 40 default: | 54 default: |
| 41 NOTREACHED() << "Layout not supported: " << media_layout; | 55 NOTREACHED() << "Layout not supported: " << media_layout; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 capture_thread_checker_.DetachFromThread(); | 258 capture_thread_checker_.DetachFromThread(); |
| 245 render_thread_checker_.DetachFromThread(); | 259 render_thread_checker_.DetachFromThread(); |
| 246 InitializeAudioProcessingModule(constraints, input_params); | 260 InitializeAudioProcessingModule(constraints, input_params); |
| 247 | 261 |
| 248 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); | 262 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); |
| 249 // In unit tests not creating a message filter, |aec_dump_message_filter_| | 263 // In unit tests not creating a message filter, |aec_dump_message_filter_| |
| 250 // will be NULL. We can just ignore that. Other unit tests and browser tests | 264 // will be NULL. We can just ignore that. Other unit tests and browser tests |
| 251 // ensure that we do get the filter when we should. | 265 // ensure that we do get the filter when we should. |
| 252 if (aec_dump_message_filter_.get()) | 266 if (aec_dump_message_filter_.get()) |
| 253 aec_dump_message_filter_->AddDelegate(this); | 267 aec_dump_message_filter_->AddDelegate(this); |
| 268 | |
| 269 // Create and configure |audio_repetition_reporter_|. | |
| 270 std::vector<int> look_back_times; | |
| 271 for (int time = kMaxLookbackTimeMs; time >= kMinLookbackTimeMs; | |
| 272 time -= kLookbackTimeStepMs) { | |
| 273 look_back_times.push_back(time); | |
| 274 } | |
| 275 audio_repetition_reporter_.reset( | |
| 276 new AudioRepetitionReporter(kMinLengthMs, kMaxFrames, &look_back_times[0], | |
| 277 look_back_times.size())); | |
| 254 } | 278 } |
| 255 | 279 |
| 256 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 280 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
| 257 DCHECK(main_thread_checker_.CalledOnValidThread()); | 281 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 258 Stop(); | 282 Stop(); |
| 259 } | 283 } |
| 260 | 284 |
| 261 void MediaStreamAudioProcessor::OnCaptureFormatChanged( | 285 void MediaStreamAudioProcessor::OnCaptureFormatChanged( |
| 262 const media::AudioParameters& input_format) { | 286 const media::AudioParameters& input_format) { |
| 263 DCHECK(main_thread_checker_.CalledOnValidThread()); | 287 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 289 DCHECK(processed_data); | 313 DCHECK(processed_data); |
| 290 DCHECK(capture_delay); | 314 DCHECK(capture_delay); |
| 291 DCHECK(new_volume); | 315 DCHECK(new_volume); |
| 292 | 316 |
| 293 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); | 317 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); |
| 294 | 318 |
| 295 MediaStreamAudioBus* process_bus; | 319 MediaStreamAudioBus* process_bus; |
| 296 if (!capture_fifo_->Consume(&process_bus, capture_delay)) | 320 if (!capture_fifo_->Consume(&process_bus, capture_delay)) |
| 297 return false; | 321 return false; |
| 298 | 322 |
| 323 // Detect bit-exact repetition of audio present in the captured audio. | |
| 324 // We detect only one channel. | |
| 325 audio_repetition_reporter_->Detect(process_bus->bus()->channel(0), | |
| 326 process_bus->bus()->frames(), | |
| 327 1, // number of channels | |
| 328 input_format_.sample_rate()); | |
| 329 | |
| 299 // Use the process bus directly if audio processing is disabled. | 330 // Use the process bus directly if audio processing is disabled. |
| 300 MediaStreamAudioBus* output_bus = process_bus; | 331 MediaStreamAudioBus* output_bus = process_bus; |
| 301 *new_volume = 0; | 332 *new_volume = 0; |
| 302 if (audio_processing_) { | 333 if (audio_processing_) { |
| 303 output_bus = output_bus_.get(); | 334 output_bus = output_bus_.get(); |
| 304 *new_volume = ProcessData(process_bus->channel_ptrs(), | 335 *new_volume = ProcessData(process_bus->channel_ptrs(), |
| 305 process_bus->bus()->frames(), *capture_delay, | 336 process_bus->bus()->frames(), *capture_delay, |
| 306 volume, key_pressed, output_bus->channel_ptrs()); | 337 volume, key_pressed, output_bus->channel_ptrs()); |
| 307 } | 338 } |
| 308 | 339 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 DCHECK(main_thread_checker_.CalledOnValidThread()); | 398 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 368 if (audio_processing_) | 399 if (audio_processing_) |
| 369 StopEchoCancellationDump(audio_processing_.get()); | 400 StopEchoCancellationDump(audio_processing_.get()); |
| 370 } | 401 } |
| 371 | 402 |
| 372 void MediaStreamAudioProcessor::OnIpcClosing() { | 403 void MediaStreamAudioProcessor::OnIpcClosing() { |
| 373 DCHECK(main_thread_checker_.CalledOnValidThread()); | 404 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 374 aec_dump_message_filter_ = NULL; | 405 aec_dump_message_filter_ = NULL; |
| 375 } | 406 } |
| 376 | 407 |
| 408 MediaStreamAudioProcessor::AudioRepetitionReporter::AudioRepetitionReporter( | |
| 409 int min_length_ms, size_t max_frames, const int* look_back_times, | |
| 410 size_t num_look_back) | |
| 411 : AudioRepetitionDetector(min_length_ms, max_frames, look_back_times, | |
| 412 num_look_back) { | |
| 413 } | |
| 414 | |
| 415 void MediaStreamAudioProcessor::AudioRepetitionReporter::ReportRepetition( | |
| 416 int look_back_ms) { | |
| 417 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 418 "Media.AudioCapturerRepetition", look_back_ms, | |
| 419 kMinLookbackTimeMs, kMaxLookbackTimeMs, | |
| 420 (kMaxLookbackTimeMs - kMinLookbackTimeMs) / kLookbackTimeStepMs + 1); | |
| 421 } | |
| 422 | |
| 377 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, | 423 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
| 378 int sample_rate, | 424 int sample_rate, |
| 379 int audio_delay_milliseconds) { | 425 int audio_delay_milliseconds) { |
| 380 DCHECK(render_thread_checker_.CalledOnValidThread()); | 426 DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 381 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ | 427 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ |
| 382 audio_processing_->echo_cancellation()->is_enabled()); | 428 audio_processing_->echo_cancellation()->is_enabled()); |
| 383 | 429 |
| 384 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); | 430 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); |
| 385 DCHECK_LT(audio_delay_milliseconds, | 431 DCHECK_LT(audio_delay_milliseconds, |
| 386 std::numeric_limits<base::subtle::Atomic32>::max()); | 432 std::numeric_limits<base::subtle::Atomic32>::max()); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 if (echo_information_) { | 724 if (echo_information_) { |
| 679 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); | 725 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); |
| 680 } | 726 } |
| 681 | 727 |
| 682 // Return 0 if the volume hasn't been changed, and otherwise the new volume. | 728 // Return 0 if the volume hasn't been changed, and otherwise the new volume. |
| 683 return (agc->stream_analog_level() == volume) ? | 729 return (agc->stream_analog_level() == volume) ? |
| 684 0 : agc->stream_analog_level(); | 730 0 : agc->stream_analog_level(); |
| 685 } | 731 } |
| 686 | 732 |
| 687 } // namespace content | 733 } // namespace content |
| OLD | NEW |