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

Side by Side Diff: webrtc/modules/audio_mixer/audio_mixer_impl.h

Issue 2692333002: Optionally disable APM limiter in AudioMixer. (Closed)
Patch Set: Fix int16_t <-> size_t compilation warnings. Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_mixer/BUILD.gn ('k') | webrtc/modules/audio_mixer/audio_mixer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_MIXER_AUDIO_MIXER_IMPL_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ 12 #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/api/audio/audio_mixer.h" 17 #include "webrtc/api/audio/audio_mixer.h"
18 #include "webrtc/base/scoped_ref_ptr.h" 18 #include "webrtc/base/scoped_ref_ptr.h"
19 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
20 #include "webrtc/base/race_checker.h" 20 #include "webrtc/base/race_checker.h"
21 #include "webrtc/modules/audio_mixer/frame_combiner.h"
21 #include "webrtc/modules/audio_mixer/output_rate_calculator.h" 22 #include "webrtc/modules/audio_mixer/output_rate_calculator.h"
22 #include "webrtc/modules/audio_processing/include/audio_processing.h" 23 #include "webrtc/modules/audio_processing/include/audio_processing.h"
23 #include "webrtc/modules/include/module_common_types.h" 24 #include "webrtc/modules/include/module_common_types.h"
24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
25 #include "webrtc/typedefs.h" 26 #include "webrtc/typedefs.h"
26 27
27 namespace webrtc { 28 namespace webrtc {
28 29
29 typedef std::vector<AudioFrame*> AudioFrameList; 30 typedef std::vector<AudioFrame*> AudioFrameList;
30 31
(...skipping 10 matching lines...) Expand all
41 AudioFrame audio_frame; 42 AudioFrame audio_frame;
42 }; 43 };
43 44
44 using SourceStatusList = std::vector<std::unique_ptr<SourceStatus>>; 45 using SourceStatusList = std::vector<std::unique_ptr<SourceStatus>>;
45 46
46 // AudioProcessing only accepts 10 ms frames. 47 // AudioProcessing only accepts 10 ms frames.
47 static const int kFrameDurationInMs = 10; 48 static const int kFrameDurationInMs = 10;
48 static const int kMaximumAmountOfMixedAudioSources = 3; 49 static const int kMaximumAmountOfMixedAudioSources = 3;
49 50
50 static rtc::scoped_refptr<AudioMixerImpl> Create(); 51 static rtc::scoped_refptr<AudioMixerImpl> Create();
51 static rtc::scoped_refptr<AudioMixerImpl> CreateWithOutputRateCalculator( 52
53 // TODO(aleloi): remove this when dependencies have updated to
54 // use Create..AndLimiter instead. See bugs.webrtc.org/7167.
55 RTC_DEPRECATED static rtc::scoped_refptr<AudioMixerImpl>
56 CreateWithOutputRateCalculator(
52 std::unique_ptr<OutputRateCalculator> output_rate_calculator); 57 std::unique_ptr<OutputRateCalculator> output_rate_calculator);
53 58
59 static rtc::scoped_refptr<AudioMixerImpl>
60 CreateWithOutputRateCalculatorAndLimiter(
61 std::unique_ptr<OutputRateCalculator> output_rate_calculator,
62 bool use_limiter);
63
54 ~AudioMixerImpl() override; 64 ~AudioMixerImpl() override;
55 65
56 // AudioMixer functions 66 // AudioMixer functions
57 bool AddSource(Source* audio_source) override; 67 bool AddSource(Source* audio_source) override;
58 void RemoveSource(Source* audio_source) override; 68 void RemoveSource(Source* audio_source) override;
59 69
60 void Mix(size_t number_of_channels, 70 void Mix(size_t number_of_channels,
61 AudioFrame* audio_frame_for_mixing) override LOCKS_EXCLUDED(crit_); 71 AudioFrame* audio_frame_for_mixing) override LOCKS_EXCLUDED(crit_);
62 72
63 // Returns true if the source was mixed last round. Returns 73 // Returns true if the source was mixed last round. Returns
64 // false and logs an error if the source was never added to the 74 // false and logs an error if the source was never added to the
65 // mixer. 75 // mixer.
66 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const; 76 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const;
67 77
68 protected: 78 protected:
69 AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter, 79 AudioMixerImpl(std::unique_ptr<OutputRateCalculator> output_rate_calculator,
70 std::unique_ptr<OutputRateCalculator> output_rate_calculator); 80 bool use_limiter);
71 81
72 private: 82 private:
73 // Set mixing frequency through OutputFrequencyCalculator. 83 // Set mixing frequency through OutputFrequencyCalculator.
74 void CalculateOutputFrequency(); 84 void CalculateOutputFrequency();
75 // Get mixing frequency. 85 // Get mixing frequency.
76 int OutputFrequency() const; 86 int OutputFrequency() const;
77 87
78 // Compute what audio sources to mix from audio_source_list_. Ramp 88 // Compute what audio sources to mix from audio_source_list_. Ramp
79 // in and out. Update mixed status. Mixes up to 89 // in and out. Update mixed status. Mixes up to
80 // kMaximumAmountOfMixedAudioSources audio sources. 90 // kMaximumAmountOfMixedAudioSources audio sources.
81 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_); 91 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_);
82 92
83 // Add/remove the MixerAudioSource to the specified 93 // Add/remove the MixerAudioSource to the specified
84 // MixerAudioSource list. 94 // MixerAudioSource list.
85 bool AddAudioSourceToList(Source* audio_source, 95 bool AddAudioSourceToList(Source* audio_source,
86 SourceStatusList* audio_source_list) const; 96 SourceStatusList* audio_source_list) const;
87 bool RemoveAudioSourceFromList(Source* remove_audio_source, 97 bool RemoveAudioSourceFromList(Source* remove_audio_source,
88 SourceStatusList* audio_source_list) const; 98 SourceStatusList* audio_source_list) const;
89 99
90 bool LimitMixedAudio(AudioFrame* mixed_audio) const;
91
92 // The critical section lock guards audio source insertion and 100 // The critical section lock guards audio source insertion and
93 // removal, which can be done from any thread. The race checker 101 // removal, which can be done from any thread. The race checker
94 // checks that mixing is done sequentially. 102 // checks that mixing is done sequentially.
95 rtc::CriticalSection crit_; 103 rtc::CriticalSection crit_;
96 rtc::RaceChecker race_checker_; 104 rtc::RaceChecker race_checker_;
97 105
98 std::unique_ptr<OutputRateCalculator> output_rate_calculator_; 106 std::unique_ptr<OutputRateCalculator> output_rate_calculator_;
99 // The current sample frequency and sample size when mixing. 107 // The current sample frequency and sample size when mixing.
100 int output_frequency_ GUARDED_BY(race_checker_); 108 int output_frequency_ GUARDED_BY(race_checker_);
101 size_t sample_size_ GUARDED_BY(race_checker_); 109 size_t sample_size_ GUARDED_BY(race_checker_);
102 110
103 // List of all audio sources. Note all lists are disjunct 111 // List of all audio sources. Note all lists are disjunct
104 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. 112 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed.
105 113
106 // Determines if we will use a limiter for clipping protection during 114 // Component that handles actual adding of audio frames.
107 // mixing. 115 FrameCombiner frame_combiner_ GUARDED_BY(race_checker_);
108 bool use_limiter_ GUARDED_BY(race_checker_);
109
110 uint32_t time_stamp_ GUARDED_BY(race_checker_);
111
112 // Used for inhibiting saturation in mixing.
113 std::unique_ptr<AudioProcessing> limiter_ GUARDED_BY(race_checker_);
114 116
115 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); 117 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl);
116 }; 118 };
117 } // namespace webrtc 119 } // namespace webrtc
118 120
119 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ 121 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/BUILD.gn ('k') | webrtc/modules/audio_mixer/audio_mixer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698