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..1bf82bce5db6c01f84c26f62bbb42c1538597331 100644 |
| --- a/content/renderer/media/media_stream_audio_processor.cc |
| +++ b/content/renderer/media/media_stream_audio_processor.cc |
| @@ -29,6 +29,20 @@ using webrtc::NoiseSuppression; |
| const int kAudioProcessingNumberOfChannels = 1; |
| +// 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
|
| +const int kMinLengthMs = 1; |
| + |
| +// The following variables defines the look back time of 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. Input longer than |kMaxFrames| |
| +// won't cause any problem, and will only affect computational efficiency. |
| +const size_t kMaxFrames = 480; // 10 ms * 48 kHz |
| + |
| AudioProcessing::ChannelLayout MapLayout(media::ChannelLayout media_layout) { |
| switch (media_layout) { |
| case media::CHANNEL_LAYOUT_MONO: |
| @@ -251,6 +265,16 @@ 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_reporter_|. |
| + std::vector<int> look_back_times; |
| + for (int time = kMaxLookbackTimeMs; time >= kMinLookbackTimeMs; |
| + time -= kLookbackTimeStepMs) { |
| + look_back_times.push_back(time); |
| + } |
| + audio_repetition_reporter_.reset( |
| + new AudioRepetitionReporter(kMinLengthMs, kMaxFrames, &look_back_times[0], |
| + look_back_times.size())); |
| } |
| MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
| @@ -296,6 +320,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_reporter_->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; |
| @@ -374,6 +405,21 @@ void MediaStreamAudioProcessor::OnIpcClosing() { |
| aec_dump_message_filter_ = NULL; |
| } |
| +MediaStreamAudioProcessor::AudioRepetitionReporter::AudioRepetitionReporter( |
| + int min_length_ms, size_t max_frames, const int* look_back_times, |
| + size_t num_look_back) |
| + : AudioRepetitionDetector(min_length_ms, max_frames, look_back_times, |
| + num_look_back) { |
| +} |
| + |
| +void MediaStreamAudioProcessor::AudioRepetitionReporter::ReportRepetition( |
| + int look_back_ms) { |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "Media.AudioCapturerRepetition", look_back_ms, |
| + kMinLookbackTimeMs, kMaxLookbackTimeMs, |
| + (kMaxLookbackTimeMs - kMinLookbackTimeMs) / kLookbackTimeStepMs + 1); |
| +} |
| + |
| void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
| int sample_rate, |
| int audio_delay_milliseconds) { |