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