OLD | NEW |
---|---|
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_GAIN_CONTROL_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/scoped_ptr.h" | |
17 #include "webrtc/common_audio/swap_queue.h" | |
16 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 18 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
17 #include "webrtc/modules/audio_processing/processing_component.h" | 19 #include "webrtc/modules/audio_processing/processing_component.h" |
18 | 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
23 namespace { | |
24 // Functor to use when supplying a verifier function for the queue item | |
25 // verifcation. | |
26 class AgcRenderQueueItemVerifier { | |
27 public: | |
28 explicit AgcRenderQueueItemVerifier(size_t allowed_size_1, | |
29 size_t allowed_size_2) | |
30 : allowed_size_1_(allowed_size_1), allowed_size_2_(allowed_size_2) {} | |
31 | |
32 bool operator()(const std::vector<int16_t>& v) const { | |
33 return (((v.size() == allowed_size_1_) || (v.size() == allowed_size_2_)) && | |
the sun
2015/10/27 16:42:49
Like said in another review: you only need to asse
peah-webrtc
2015/10/29 14:05:23
Good find! This has now been refactored.
Done.
| |
34 (v.capacity() >= std::max(allowed_size_1_, allowed_size_2_))); | |
35 } | |
36 | |
37 private: | |
38 size_t allowed_size_1_; | |
39 size_t allowed_size_2_; | |
40 }; | |
41 | |
42 } // namespace anonymous | |
43 | |
21 class AudioBuffer; | 44 class AudioBuffer; |
22 class CriticalSectionWrapper; | 45 class CriticalSectionWrapper; |
23 | 46 |
24 class GainControlImpl : public GainControl, | 47 class GainControlImpl : public GainControl, |
25 public ProcessingComponent { | 48 public ProcessingComponent { |
26 public: | 49 public: |
27 GainControlImpl(const AudioProcessing* apm, | 50 GainControlImpl(const AudioProcessing* apm, |
28 CriticalSectionWrapper* crit); | 51 CriticalSectionWrapper* crit); |
29 virtual ~GainControlImpl(); | 52 virtual ~GainControlImpl(); |
30 | 53 |
31 int ProcessRenderAudio(AudioBuffer* audio); | 54 int ProcessRenderAudio(AudioBuffer* audio); |
32 int AnalyzeCaptureAudio(AudioBuffer* audio); | 55 int AnalyzeCaptureAudio(AudioBuffer* audio); |
33 int ProcessCaptureAudio(AudioBuffer* audio); | 56 int ProcessCaptureAudio(AudioBuffer* audio); |
34 | 57 |
35 // ProcessingComponent implementation. | 58 // ProcessingComponent implementation. |
36 int Initialize() override; | 59 int Initialize() override; |
37 | 60 |
38 // GainControl implementation. | 61 // GainControl implementation. |
39 bool is_enabled() const override; | 62 bool is_enabled() const override; |
40 int stream_analog_level() override; | 63 int stream_analog_level() override; |
41 bool is_limiter_enabled() const override; | 64 bool is_limiter_enabled() const override; |
42 Mode mode() const override; | 65 Mode mode() const override; |
43 | 66 |
67 // Reads render side data that has been queued on the render call. | |
68 void ReadQueuedRenderData(); | |
69 | |
44 private: | 70 private: |
71 static const size_t kAllowedValuesOfSamplesPerFrame1 = 80; | |
72 static const size_t kAllowedValuesOfSamplesPerFrame2 = 160; | |
73 // TODO(peah): Decrease this once we properly handle hugely unbalanced | |
74 // reverse and forward call numbers. | |
75 static const size_t kMaxNumFramesToBuffer = 100; | |
76 | |
45 // GainControl implementation. | 77 // GainControl implementation. |
46 int Enable(bool enable) override; | 78 int Enable(bool enable) override; |
47 int set_stream_analog_level(int level) override; | 79 int set_stream_analog_level(int level) override; |
48 int set_mode(Mode mode) override; | 80 int set_mode(Mode mode) override; |
49 int set_target_level_dbfs(int level) override; | 81 int set_target_level_dbfs(int level) override; |
50 int target_level_dbfs() const override; | 82 int target_level_dbfs() const override; |
51 int set_compression_gain_db(int gain) override; | 83 int set_compression_gain_db(int gain) override; |
52 int compression_gain_db() const override; | 84 int compression_gain_db() const override; |
53 int enable_limiter(bool enable) override; | 85 int enable_limiter(bool enable) override; |
54 int set_analog_level_limits(int minimum, int maximum) override; | 86 int set_analog_level_limits(int minimum, int maximum) override; |
55 int analog_level_minimum() const override; | 87 int analog_level_minimum() const override; |
56 int analog_level_maximum() const override; | 88 int analog_level_maximum() const override; |
57 bool stream_is_saturated() const override; | 89 bool stream_is_saturated() const override; |
58 | 90 |
59 // ProcessingComponent implementation. | 91 // ProcessingComponent implementation. |
60 void* CreateHandle() const override; | 92 void* CreateHandle() const override; |
61 int InitializeHandle(void* handle) const override; | 93 int InitializeHandle(void* handle) const override; |
62 int ConfigureHandle(void* handle) const override; | 94 int ConfigureHandle(void* handle) const override; |
63 void DestroyHandle(void* handle) const override; | 95 void DestroyHandle(void* handle) const override; |
64 int num_handles_required() const override; | 96 int num_handles_required() const override; |
65 int GetHandleError(void* handle) const override; | 97 int GetHandleError(void* handle) const override; |
66 | 98 |
99 void AllocateRenderQueue(); | |
100 | |
67 const AudioProcessing* apm_; | 101 const AudioProcessing* apm_; |
68 CriticalSectionWrapper* crit_; | 102 CriticalSectionWrapper* crit_; |
69 Mode mode_; | 103 Mode mode_; |
70 int minimum_capture_level_; | 104 int minimum_capture_level_; |
71 int maximum_capture_level_; | 105 int maximum_capture_level_; |
72 bool limiter_enabled_; | 106 bool limiter_enabled_; |
73 int target_level_dbfs_; | 107 int target_level_dbfs_; |
74 int compression_gain_db_; | 108 int compression_gain_db_; |
75 std::vector<int> capture_levels_; | 109 std::vector<int> capture_levels_; |
76 int analog_capture_level_; | 110 int analog_capture_level_; |
77 bool was_analog_level_set_; | 111 bool was_analog_level_set_; |
78 bool stream_is_saturated_; | 112 bool stream_is_saturated_; |
113 | |
114 size_t render_queue_element_max_size_; | |
115 std::vector<int16_t> render_queue_buffer_; | |
116 std::vector<int16_t> capture_queue_buffer_; | |
117 rtc::scoped_ptr<SwapQueue<std::vector<int16_t>, AgcRenderQueueItemVerifier> > | |
118 render_signal_queue_; | |
79 }; | 119 }; |
80 } // namespace webrtc | 120 } // namespace webrtc |
81 | 121 |
82 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 122 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
OLD | NEW |