OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_ | |
6 #define CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/memory/scoped_vector.h" | |
11 #include "content/common/content_export.h" | |
12 | |
13 namespace content { | |
14 | |
15 class RepetitionDetectorForTest; | |
Henrik Grunell
2015/09/23 10:36:42
Remove.
minyue
2015/09/25 14:40:08
Done.
| |
16 | |
17 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.
| |
18 public: | |
19 RepetitionDetector(); | |
20 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
| |
21 | |
22 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
| |
23 int id_; | |
24 // 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.
| |
25 // supposedly bounded to certain duration in time. | |
26 int look_back_ms_; | |
27 int min_length_ms_; | |
28 }; | |
29 | |
30 // Detect repetition in |data|. When multichannel, samples should be | |
31 // 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.
| |
32 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
| |
33 int sample_rate_hz); | |
34 | |
35 private: | |
36 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
| |
37 | |
38 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.
| |
39 public: | |
40 State(int id, int look_back_ms, int min_length_ms); | |
41 | |
42 bool reported() const { return reported_; } | |
43 void set_reported(bool reported) { reported_ = reported; } | |
44 | |
45 // Increase the counter by 1, and tell if the counted audio is zero. | |
46 void Increment(bool zero); | |
47 | |
48 bool HasValidReport(int sample_rate_khz) const; | |
49 | |
50 void Reset(); | |
51 int id() const { return id_; } | |
52 int look_back_ms() const { return look_back_ms_; } | |
53 | |
54 private: | |
55 const int id_; | |
Henrik Grunell
2015/09/23 10:36:42
Comment on all member variables.
minyue
2015/09/25 14:40:08
Done.
| |
56 const int look_back_ms_; | |
57 const int min_length_ms_; | |
58 size_t count_frames_; | |
59 bool all_zero_; | |
60 bool reported_; | |
61 }; | |
62 | |
63 void RegisterRepetitionPatterns(const Pattern* patterns, | |
64 size_t num_patterns); | |
65 | |
66 void ClearRepetitionPatterns(); | |
67 | |
68 // Reset |audio_buffer_| when number of channels or sample rate changes. | |
69 void Reset(size_t num_channels, int sample_rate_hz); | |
70 | |
71 // Add frames (interleaved if stereo) to |audio_buffer_|. | |
72 void AddFramesToBuffer(const float* data, size_t num_frames); | |
73 | |
74 // Determine if an audio frame (samples interleaved if stereo) is identical to | |
75 // |audio_buffer_| at a look back position. | |
76 bool Equal(const float* frame, int look_back_samples) const; | |
77 | |
78 // Determine if an audio frame (samples interleaved if stereo) is zero. | |
79 bool IsZero(const float* frame) const; | |
80 | |
81 // Action when found repetition. | |
82 virtual void ReportRepetition(int id); | |
83 | |
84 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.
| |
85 ScopedVector<State> states_; | |
86 int max_look_back_ms_; | |
87 | |
88 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.
| |
89 size_t num_channels_; // Number of audio channels in buffer. | |
90 int sample_rate_hz_; // Sample rate in Hz. | |
91 size_t buffer_size_frames_; // Number of frames in |audio_buffer|. | |
92 size_t buffer_end_index_; // The index of the last frame in |audio_buffer|. | |
93 size_t max_frames_; // The maximum input frames that |audio_buffer_| | |
94 // can handle for each detection. | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); | |
97 }; | |
98 | |
99 } // namespace content | |
100 | |
101 #endif // CONTENT_RENDERER_MEDIA_REPETITION_DETECTOR_H_ | |
OLD | NEW |