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

Unified Diff: content/renderer/media/repetition_detector.h

Issue 1357013006: Add detection for repeated audio in capturing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing dll Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/repetition_detector.h
diff --git a/content/renderer/media/repetition_detector.h b/content/renderer/media/repetition_detector.h
new file mode 100644
index 0000000000000000000000000000000000000000..2b65011cab02559266b10f6e63e7b0cb03bdc652
--- /dev/null
+++ b/content/renderer/media/repetition_detector.h
@@ -0,0 +1,101 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_
+#define CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_
+
+#include <vector>
+
+#include "base/memory/scoped_vector.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+class RepetitionDetectorForTest;
Henrik Grunell 2015/09/23 10:36:42 Remove.
minyue 2015/09/25 14:40:08 Done.
+
+class CONTENT_EXPORT RepetitionDetector {
Henrik Grunell 2015/09/23 10:36:42 Call it AudioRepetitionDetector. (And rename files
Henrik Grunell 2015/09/23 10:36:42 Add comment describing the class briefly. Also giv
minyue 2015/09/25 14:40:08 Done.
minyue 2015/09/25 14:40:08 Done.
+ public:
+ RepetitionDetector();
+ virtual ~RepetitionDetector();
tommi (sloooow) - chröme 2015/09/25 08:57:14 Can you add documentation for the class, what it d
minyue 2015/09/25 14:40:08 Yes, also per Henrik's request. The virtual is bec
+
+ struct Pattern {
Henrik Grunell 2015/09/23 10:36:42 Can this be private?
minyue 2015/09/25 14:40:08 Not really if we want the RegisterRepetitionPatter
+ int id_;
+ // All followings are in milliseconds, since repetition patterns are
Henrik Grunell 2015/09/23 10:36:42 Move this comment to before the struct statement,
minyue 2015/09/25 14:40:08 Done.
+ // supposedly bounded to certain duration in time.
+ int look_back_ms_;
+ int min_length_ms_;
+ };
+
+ // Detect repetition in |data|. When multichannel, samples should be
+ // interleaved.
Henrik Grunell 2015/09/23 10:36:42 Describe what it does if repetition is detected.
minyue 2015/09/25 14:40:08 Done.
+ void Detect(const float* data, size_t num_frames, size_t num_channels,
Henrik Grunell 2015/09/23 10:36:42 This should take a const AudioBus*.
minyue 2015/09/25 14:40:08 See my comment on a concern of making input format
+ int sample_rate_hz);
+
+ private:
+ friend class RepetitionDetectorForTest; // For testing.
Henrik Grunell 2015/09/23 10:36:42 Should you use FRIEND_TEST_ALL_PREFIXES()? See oth
minyue 2015/09/25 14:40:08 This has been considered and discussed in the para
tommi (sloooow) - chröme 2015/09/28 10:28:39 Did you discuss making the parts that the derived
minyue 2015/09/28 14:47:50 I used protected, and reviewers wanted me to use F
+
+ class State {
Henrik Grunell 2015/09/23 10:36:42 Comment and describe the class and what it's used
minyue 2015/09/25 14:40:08 Done.
+ public:
+ State(int id, int look_back_ms, int min_length_ms);
+
+ bool reported() const { return reported_; }
+ void set_reported(bool reported) { reported_ = reported; }
+
+ // Increase the counter by 1, and tell if the counted audio is zero.
+ void Increment(bool zero);
+
+ bool HasValidReport(int sample_rate_khz) const;
+
+ void Reset();
+ int id() const { return id_; }
+ int look_back_ms() const { return look_back_ms_; }
+
+ private:
+ const int id_;
Henrik Grunell 2015/09/23 10:36:42 Comment on all member variables.
minyue 2015/09/25 14:40:08 Done.
+ const int look_back_ms_;
+ const int min_length_ms_;
+ size_t count_frames_;
+ bool all_zero_;
+ bool reported_;
+ };
+
+ void RegisterRepetitionPatterns(const Pattern* patterns,
+ size_t num_patterns);
+
+ void ClearRepetitionPatterns();
+
+ // Reset |audio_buffer_| when number of channels or sample rate changes.
+ void Reset(size_t num_channels, int sample_rate_hz);
+
+ // Add frames (interleaved if stereo) to |audio_buffer_|.
+ void AddFramesToBuffer(const float* data, size_t num_frames);
+
+ // Determine if an audio frame (samples interleaved if stereo) is identical to
+ // |audio_buffer_| at a look back position.
+ bool Equal(const float* frame, int look_back_samples) const;
+
+ // Determine if an audio frame (samples interleaved if stereo) is zero.
+ bool IsZero(const float* frame) const;
+
+ // Action when found repetition.
+ virtual void ReportRepetition(int id);
+
+ std::vector<int> ids_;
Henrik Grunell 2015/09/23 10:36:42 Comment on all member variables.
minyue 2015/09/25 14:40:08 Done.
+ ScopedVector<State> states_;
+ int max_look_back_ms_;
+
+ std::vector<float> audio_buffer_; // Ring buffers to store input audio.
Henrik Grunell 2015/09/23 10:36:42 Put comments on its own line before the variable.
minyue 2015/09/25 14:40:08 Done.
+ size_t num_channels_; // Number of audio channels in buffer.
+ int sample_rate_hz_; // Sample rate in Hz.
+ size_t buffer_size_frames_; // Number of frames in |audio_buffer|.
+ size_t buffer_end_index_; // The index of the last frame in |audio_buffer|.
+ size_t max_frames_; // The maximum input frames that |audio_buffer_|
+ // can handle for each detection.
+
+ DISALLOW_COPY_AND_ASSIGN(RepetitionDetector);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698