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_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 <map> | |
15 #include <memory> | 14 #include <memory> |
16 #include <vector> | 15 #include <vector> |
17 | 16 |
18 #include "webrtc/base/thread_annotations.h" | 17 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/base/thread_checker.h" | 18 #include "webrtc/base/thread_checker.h" |
20 #include "webrtc/modules/audio_mixer/audio_mixer.h" | 19 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
21 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 20 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
22 #include "webrtc/modules/include/module_common_types.h" | 21 #include "webrtc/modules/include/module_common_types.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
24 #include "webrtc/voice_engine/level_indicator.h" | 23 #include "webrtc/voice_engine/level_indicator.h" |
(...skipping 10 matching lines...) Expand all Loading... |
35 : audio_source(audio_source), is_mixed(is_mixed), gain(gain) {} | 34 : audio_source(audio_source), is_mixed(is_mixed), gain(gain) {} |
36 Source* audio_source = nullptr; | 35 Source* audio_source = nullptr; |
37 bool is_mixed = false; | 36 bool is_mixed = false; |
38 float gain = 0.0f; | 37 float gain = 0.0f; |
39 }; | 38 }; |
40 | 39 |
41 typedef std::vector<SourceStatus> SourceStatusList; | 40 typedef std::vector<SourceStatus> SourceStatusList; |
42 | 41 |
43 // AudioProcessing only accepts 10 ms frames. | 42 // AudioProcessing only accepts 10 ms frames. |
44 static const int kFrameDurationInMs = 10; | 43 static const int kFrameDurationInMs = 10; |
| 44 static const int kDefaultFrequency = 48000; |
45 | 45 |
46 static std::unique_ptr<AudioMixerImpl> Create(int id); | 46 static std::unique_ptr<AudioMixerImpl> Create(); |
47 | 47 |
48 ~AudioMixerImpl() override; | 48 ~AudioMixerImpl() override; |
49 | 49 |
50 // AudioMixer functions | 50 // AudioMixer functions |
51 int32_t SetMixabilityStatus(Source* audio_source, bool mixable) override; | 51 int32_t SetMixabilityStatus(Source* audio_source, bool mixable) override; |
52 bool MixabilityStatus(const Source& audio_source) const override; | |
53 int32_t SetAnonymousMixabilityStatus(Source* audio_source, | |
54 bool mixable) override; | |
55 void Mix(int sample_rate, | 52 void Mix(int sample_rate, |
56 size_t number_of_channels, | 53 size_t number_of_channels, |
57 AudioFrame* audio_frame_for_mixing) override; | 54 AudioFrame* audio_frame_for_mixing) override; |
58 bool AnonymousMixabilityStatus(const Source& audio_source) const override; | |
59 | 55 |
60 // Returns true if the source was mixed last round. Returns | 56 // Returns true if the source was mixed last round. Returns |
61 // false and logs an error if the source was never added to the | 57 // false and logs an error if the source was never added to the |
62 // mixer. | 58 // mixer. |
63 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source); | 59 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const; |
64 | 60 |
65 private: | 61 private: |
66 AudioMixerImpl(int id, std::unique_ptr<AudioProcessing> limiter); | 62 explicit AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter); |
67 | 63 |
68 // Set/get mix frequency | 64 // Set/get mix frequency |
69 int32_t SetOutputFrequency(const Frequency& frequency); | 65 void SetOutputFrequency(int frequency); |
70 Frequency OutputFrequency() const; | 66 int OutputFrequency() const; |
71 | 67 |
72 // Compute what audio sources to mix from audio_source_list_. Ramp | 68 // Compute what audio sources to mix from audio_source_list_. Ramp |
73 // in and out. Update mixed status. Mixes up to | 69 // in and out. Update mixed status. Mixes up to |
74 // kMaximumAmountOfMixedAudioSources audio sources. | 70 // kMaximumAmountOfMixedAudioSources audio sources. |
75 AudioFrameList GetNonAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 71 AudioFrameList GetNonAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
76 | 72 |
77 // Return the AudioFrames that should be mixed anonymously. Ramp in | |
78 // and out. Update mixed status. | |
79 AudioFrameList GetAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
80 | 73 |
81 // Add/remove the MixerAudioSource to the specified | 74 // Add/remove the MixerAudioSource to the specified |
82 // MixerAudioSource list. | 75 // MixerAudioSource list. |
83 bool AddAudioSourceToList(Source* audio_source, | 76 bool AddAudioSourceToList(Source* audio_source, |
84 SourceStatusList* audio_source_list) const; | 77 SourceStatusList* audio_source_list) const; |
85 bool RemoveAudioSourceFromList(Source* remove_audio_source, | 78 bool RemoveAudioSourceFromList(Source* remove_audio_source, |
86 SourceStatusList* audio_source_list) const; | 79 SourceStatusList* audio_source_list) const; |
87 | 80 |
88 bool LimitMixedAudio(AudioFrame* mixed_audio) const; | 81 bool LimitMixedAudio(AudioFrame* mixed_audio) const; |
89 | 82 |
90 // Output level functions for VoEVolumeControl. | |
91 int GetOutputAudioLevel() override; | |
92 | |
93 int GetOutputAudioLevelFullRange() override; | |
94 | 83 |
95 rtc::CriticalSection crit_; | 84 rtc::CriticalSection crit_; |
96 | 85 |
97 const int32_t id_; | |
98 | |
99 // The current sample frequency and sample size when mixing. | 86 // The current sample frequency and sample size when mixing. |
100 Frequency output_frequency_ ACCESS_ON(&thread_checker_); | 87 int output_frequency_ ACCESS_ON(&thread_checker_); |
101 size_t sample_size_ ACCESS_ON(&thread_checker_); | 88 size_t sample_size_ ACCESS_ON(&thread_checker_); |
102 | 89 |
103 // List of all audio sources. Note all lists are disjunct | 90 // List of all audio sources. Note all lists are disjunct |
104 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. | 91 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. |
105 | 92 |
106 // Always mixed, anonymously. | |
107 SourceStatusList additional_audio_source_list_ GUARDED_BY(crit_); | |
108 | |
109 size_t num_mixed_audio_sources_ GUARDED_BY(crit_); | 93 size_t num_mixed_audio_sources_ GUARDED_BY(crit_); |
110 // Determines if we will use a limiter for clipping protection during | 94 // Determines if we will use a limiter for clipping protection during |
111 // mixing. | 95 // mixing. |
112 bool use_limiter_ ACCESS_ON(&thread_checker_); | 96 bool use_limiter_ ACCESS_ON(&thread_checker_); |
113 | 97 |
114 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); | 98 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); |
115 | 99 |
116 // Ensures that Mix is called from the same thread. | 100 // Ensures that Mix is called from the same thread. |
117 rtc::ThreadChecker thread_checker_; | 101 rtc::ThreadChecker thread_checker_; |
118 | 102 |
119 // Used for inhibiting saturation in mixing. | 103 // Used for inhibiting saturation in mixing. |
120 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); | 104 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); |
121 | 105 |
122 // Measures audio level for the combined signal. | |
123 voe::AudioLevel audio_level_ ACCESS_ON(&thread_checker_); | |
124 | |
125 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); | 106 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); |
126 }; | 107 }; |
127 } // namespace webrtc | 108 } // namespace webrtc |
128 | 109 |
129 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ | 110 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ |
OLD | NEW |