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

Side by Side Diff: webrtc/modules/audio_processing/echo_cancellation_impl.h

Issue 1424663003: Lock scheme #8: Introduced the new locking scheme (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@add_threadcheckers_CL
Patch Set: Major general updates, completing the locking scheme, and increasing readability Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
13 13
14 #include "webrtc/base/scoped_ptr.h" 14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/base/thread_annotations.h"
hlundin-webrtc 2015/11/05 16:11:22 You're not using any of this, right?
peah-webrtc 2015/11/06 09:54:32 Done.
15 #include "webrtc/base/thread_checker.h" 16 #include "webrtc/base/thread_checker.h"
16 #include "webrtc/common_audio/swap_queue.h" 17 #include "webrtc/common_audio/swap_queue.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h" 18 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/modules/audio_processing/processing_component.h" 19 #include "webrtc/modules/audio_processing/processing_component.h"
19 20
20 namespace webrtc { 21 namespace webrtc {
21 22
22 namespace { 23 namespace {
23 // Functor to use when supplying a verifier function for the queue item 24 // Functor to use when supplying a verifier function for the queue item
24 // verifcation. 25 // verifcation.
25 class AecRenderQueueItemVerifier { 26 class AecRenderQueueItemVerifier {
26 public: 27 public:
27 explicit AecRenderQueueItemVerifier(size_t minimum_capacity) 28 explicit AecRenderQueueItemVerifier(size_t minimum_capacity)
28 : minimum_capacity_(minimum_capacity) {} 29 : minimum_capacity_(minimum_capacity) {}
29 30
30 bool operator()(const std::vector<float>& v) const { 31 bool operator()(const std::vector<float>& v) const {
31 return v.capacity() >= minimum_capacity_; 32 return v.capacity() >= minimum_capacity_;
32 } 33 }
33 34
34 private: 35 private:
35 size_t minimum_capacity_; 36 size_t minimum_capacity_;
36 }; 37 };
37 38
38 } // namespace anonymous 39 } // namespace anonymous
39 40
40 class AudioBuffer; 41 class AudioBuffer;
41 class CriticalSectionWrapper;
42 42
43 class EchoCancellationImpl : public EchoCancellation, 43 class EchoCancellationImpl : public EchoCancellation,
44 public ProcessingComponent { 44 public ProcessingComponent {
45 public: 45 public:
46 // Called holding both the capture and render locks.
46 EchoCancellationImpl(const AudioProcessing* apm, 47 EchoCancellationImpl(const AudioProcessing* apm,
47 CriticalSectionWrapper* crit, 48 rtc::CriticalSection* crit_render,
49 rtc::CriticalSection* crit_capture,
48 rtc::ThreadChecker* render_thread_checker); 50 rtc::ThreadChecker* render_thread_checker);
51
49 virtual ~EchoCancellationImpl(); 52 virtual ~EchoCancellationImpl();
50 53
51 int ProcessRenderAudio(const AudioBuffer* audio); 54 int ProcessRenderAudio(
52 int ProcessCaptureAudio(AudioBuffer* audio); 55 const AudioBuffer* audio); // Called holding the render lock.
hlundin-webrtc 2015/11/05 16:11:22 +1 for adding the comments. -1 for the ugly line b
peah-webrtc 2015/11/06 09:54:32 Sorry!!! Done.
56 int ProcessCaptureAudio(
57 AudioBuffer* audio); // Called holding the capture lock.
53 58
54 // EchoCancellation implementation. 59 // EchoCancellation implementation.
55 bool is_enabled() const override; 60 bool is_enabled()
56 int stream_drift_samples() const override; 61 const override; // Aquires both the render and capture locks.
57 SuppressionLevel suppression_level() const override; 62 int stream_drift_samples() const override; // Aquires the capture lock.
58 bool is_drift_compensation_enabled() const override; 63 SuppressionLevel suppression_level()
64 const override; // Aquires the capture lock.
65 bool is_drift_compensation_enabled()
66 const override; // Aquires the capture lock.
59 67
60 // ProcessingComponent implementation. 68 // ProcessingComponent implementation.
61 int Initialize() override; 69 int Initialize()
62 void SetExtraOptions(const Config& config) override; 70 override; // Called holding both the capture and render locks.
71 void SetExtraOptions(const Config& config)
72 override; // Conditionally acquires the capture lock.
63 73
64 bool is_delay_agnostic_enabled() const; 74 bool is_delay_agnostic_enabled()
65 bool is_extended_filter_enabled() const; 75 const; // Only called from APM. No lock required.
76 bool is_extended_filter_enabled()
77 const; // Only called from APM. No lock required.
66 78
67 // Reads render side data that has been queued on the render call. 79 // Reads render side data that has been queued on the render call.
68 void ReadQueuedRenderData(); 80 void ReadQueuedRenderData(); // Called holding the capture lock.
69 81
70 private: 82 private:
71 static const size_t kAllowedValuesOfSamplesPerFrame1 = 80; 83 static const size_t kAllowedValuesOfSamplesPerFrame1 = 80;
72 static const size_t kAllowedValuesOfSamplesPerFrame2 = 160; 84 static const size_t kAllowedValuesOfSamplesPerFrame2 = 160;
73 // TODO(peah): Decrease this once we properly handle hugely unbalanced 85 // TODO(peah): Decrease this once we properly handle hugely unbalanced
74 // reverse and forward call numbers. 86 // reverse and forward call numbers.
75 static const size_t kMaxNumFramesToBuffer = 100; 87 static const size_t kMaxNumFramesToBuffer = 100;
76 88
77 // EchoCancellation implementation. 89 // EchoCancellation implementation.
78 int Enable(bool enable) override; 90 int Enable(
79 int enable_drift_compensation(bool enable) override; 91 bool enable) override; // Aquires both the render and capture locks.
80 void set_stream_drift_samples(int drift) override; 92 int enable_drift_compensation(
81 int set_suppression_level(SuppressionLevel level) override; 93 bool enable) override; // Aquires the capture lock.
82 int enable_metrics(bool enable) override; 94 void set_stream_drift_samples(
83 bool are_metrics_enabled() const override; 95 int drift) override; // Aquires the capture lock.
84 bool stream_has_echo() const override; 96 int set_suppression_level(
85 int GetMetrics(Metrics* metrics) override; 97 SuppressionLevel level) override; // Aquires the capture lock.
86 int enable_delay_logging(bool enable) override; 98 int enable_metrics(bool enable) override; // Aquires the capture lock.
87 bool is_delay_logging_enabled() const override; 99 bool are_metrics_enabled() const override; // Aquires the capture lock.
88 int GetDelayMetrics(int* median, int* std) override; 100 bool stream_has_echo()
101 const override; // Conditionally acquires the capture lock.
102 int GetMetrics(Metrics* metrics) override; // Aquires the capture lock.
103 int enable_delay_logging(bool enable) override; // Aquires the capture lock.
104 bool is_delay_logging_enabled()
105 const override; // Only called from APM. No lock required.
89 int GetDelayMetrics(int* median, 106 int GetDelayMetrics(int* median,
90 int* std, 107 int* std) override; // Aquires the capture lock.
91 float* fraction_poor_delays) override; 108 int GetDelayMetrics(
92 struct AecCore* aec_core() const override; 109 int* median,
110 int* std,
111 float* fraction_poor_delays) override; // Aquires the capture lock.
112 struct AecCore* aec_core()
113 const override; // Only called from APM. No lock required.
93 114
94 // ProcessingComponent implementation. 115 // ProcessingComponent implementation.
95 void* CreateHandle() const override; 116 void* CreateHandle()
96 int InitializeHandle(void* handle) const override; 117 const override; // Called holding both the render and capture locks.
97 int ConfigureHandle(void* handle) const override; 118 int InitializeHandle(void* handle)
98 void DestroyHandle(void* handle) const override; 119 const override; // Called holding both the render and capture locks.
99 int num_handles_required() const override; 120 int ConfigureHandle(void* handle)
100 int GetHandleError(void* handle) const override; 121 const override; // Called holding both the render and capture locks.
122 void DestroyHandle(void* handle)
123 const override; // Called holding both the render and capture locks.
124 int num_handles_required()
125 const override; // Called holding both the render and capture locks.
126 int GetHandleError(void* handle)
127 const override; // Called holding both the render and capture locks.
101 128
102 void AllocateRenderQueue(); 129 void
130 AllocateRenderQueue(); // Called holding both the render and capture locks.
103 131
104 const AudioProcessing* apm_; 132 const AudioProcessing* apm_;
105 CriticalSectionWrapper* crit_; 133 rtc::CriticalSection* const crit_render_;
134 rtc::CriticalSection* const crit_capture_;
106 const rtc::ThreadChecker* const render_thread_checker_; 135 const rtc::ThreadChecker* const render_thread_checker_;
107 136
108 bool drift_compensation_enabled_; 137 bool drift_compensation_enabled_;
109 bool metrics_enabled_; 138 bool metrics_enabled_;
110 SuppressionLevel suppression_level_; 139 SuppressionLevel suppression_level_;
111 int stream_drift_samples_; 140 int stream_drift_samples_;
112 bool was_stream_drift_set_; 141 bool was_stream_drift_set_;
113 bool stream_has_echo_; 142 bool stream_has_echo_;
114 bool delay_logging_enabled_; 143 bool delay_logging_enabled_;
115 bool extended_filter_enabled_; 144 bool extended_filter_enabled_;
116 bool delay_agnostic_enabled_; 145 bool delay_agnostic_enabled_;
117 146
118 size_t render_queue_element_max_size_; 147 size_t render_queue_element_max_size_;
119 std::vector<float> render_queue_buffer_; 148 std::vector<float> render_queue_buffer_;
120 std::vector<float> capture_queue_buffer_; 149 std::vector<float> capture_queue_buffer_;
121 rtc::scoped_ptr<SwapQueue<std::vector<float>, AecRenderQueueItemVerifier>> 150 rtc::scoped_ptr<SwapQueue<std::vector<float>, AecRenderQueueItemVerifier> >
122 render_signal_queue_; 151 render_signal_queue_; // Lock protection not needed.
123 }; 152 };
124 153
125 } // namespace webrtc 154 } // namespace webrtc
126 155
127 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ 156 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698