Chromium Code Reviews| Index: content/renderer/media/media_stream_audio_processor.cc |
| diff --git a/content/renderer/media/media_stream_audio_processor.cc b/content/renderer/media/media_stream_audio_processor.cc |
| index 23547d1b2b6490331f28d0110284f523044e1d57..7f718318edd9af1fb9987d0a117a9d9f92fa9e84 100644 |
| --- a/content/renderer/media/media_stream_audio_processor.cc |
| +++ b/content/renderer/media/media_stream_audio_processor.cc |
| @@ -29,6 +29,32 @@ using webrtc::NoiseSuppression; |
| const int kAudioProcessingNumberOfChannels = 1; |
| +// Minimum duration of any detectable audio repetition. |
| +const int kMinLengthMs = 1; |
| + |
| +// The following variables defines the look back time of audio repetitions that |
| +// will be logged. The complexity of the detector is proportional to the number |
| +// of look back times we keep track. |
| +const int kMinLookbackTimeMs = 10; |
| +const int kMaxLookbackTimeMs = 200; |
| +const int kLookbackTimeStepMs = 10; |
| + |
| +// Maximum frames of any input chunk of audio. Used by |
| +// |MediaStreamAudioProcessor::audio_repetition_detector_|. Input longer than |
| +// |kMaxFrames| won't cause any problem, and will only affect computational |
| +// efficiency. |
| +const size_t kMaxFrames = 480; // 10 ms * 48 kHz |
| + |
| +// Send UMA report on an audio repetition being detected. |look_back_ms| |
| +// provides the look back time of the detected repetition. This function is |
| +// called back by |MediaStreamAudioProcessor::audio_repetition_detector_|. |
| +void ReportRepetition(int look_back_ms) { |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "Media.AudioCapturerRepetition", look_back_ms, |
| + kMinLookbackTimeMs, kMaxLookbackTimeMs, |
| + (kMaxLookbackTimeMs - kMinLookbackTimeMs) / kLookbackTimeStepMs + 1); |
| +} |
| + |
| AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) { |
| switch (media_layout) { |
| case media::CHANNEL_LAYOUT_MONO: |
| @@ -251,6 +277,17 @@ MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
| // ensure that we do get the filter when we should. |
| if (aec_dump_message_filter_.get()) |
| aec_dump_message_filter_->AddDelegate(this); |
| + |
| + // Create and configure |audio_repetition_detector_|. |
| + std::vector<int> look_back_times; |
| + for (int time = kMaxLookbackTimeMs; time >= kMinLookbackTimeMs; |
| + time -= kLookbackTimeStepMs) { |
| + look_back_times.push_back(time); |
| + } |
| + audio_repetition_detector_.reset( |
| + new AudioRepetitionDetector(kMinLengthMs, kMaxFrames, &look_back_times[0], |
|
Henrik Grunell
2015/10/23 13:49:02
Instead of a ptr and size, let it take a const std
minyue
2015/10/26 10:41:46
good,changed the signature
|
| + look_back_times.size(), |
| + base::Bind(&ReportRepetition))); |
| } |
| MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
| @@ -296,6 +333,13 @@ bool MediaStreamAudioProcessor::ProcessAndConsumeData( |
| if (!capture_fifo_->Consume(&process_bus, capture_delay)) |
| return false; |
| + // Detect bit-exact repetition of audio present in the captured audio. |
| + // We detect only one channel. |
| + audio_repetition_detector_->Detect(process_bus->bus()->channel(0), |
| + process_bus->bus()->frames(), |
| + 1, // number of channels |
| + input_format_.sample_rate()); |
| + |
| // Use the process bus directly if audio processing is disabled. |
| MediaStreamAudioBus* output_bus = process_bus; |
| *new_volume = 0; |