OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_MODULES_AUDIO_MIXER_SOURCE_AUDIO_CONFERENCE_MIXER_IMPL_H_ | |
12 #define WEBRTC_MODULES_AUDIO_MIXER_SOURCE_AUDIO_CONFERENCE_MIXER_IMPL_H_ | |
13 | |
14 #include <list> | |
15 #include <map> | |
16 #include <memory> | |
17 | |
18 #include "webrtc/engine_configurations.h" | |
19 #include "webrtc/modules/audio_mixer/include/audio_conference_mixer.h" | |
20 #include "webrtc/modules/audio_conference_mixer/source/memory_pool.h" | |
21 #include "webrtc/modules/audio_conference_mixer/source/time_scheduler.h" | |
22 #include "webrtc/modules/include/module_common_types.h" | |
23 | |
24 namespace webrtc { | |
25 class AudioProcessing; | |
26 class CriticalSectionWrapper; | |
27 | |
28 struct FrameAndMuteInfo { | |
29 FrameAndMuteInfo(AudioFrame* f, bool m) : frame(f), muted(m) {} | |
30 AudioFrame* frame; | |
31 bool muted; | |
32 }; | |
33 | |
34 typedef std::list<FrameAndMuteInfo> AudioFrameList; | |
35 typedef std::list<MixerAudioSource*> MixerAudioSourceList; | |
36 | |
37 // Cheshire cat implementation of MixerAudioSource's non virtual functions. | |
38 class NewMixHistory { | |
39 public: | |
40 NewMixHistory(); | |
41 ~NewMixHistory(); | |
42 | |
43 // Returns true if the participant is being mixed. | |
44 bool IsMixed() const; | |
45 | |
46 // Returns true if the participant was mixed previous mix | |
47 // iteration. | |
48 bool WasMixed() const; | |
49 | |
50 // Updates the mixed status. | |
51 int32_t SetIsMixed(bool mixed); | |
52 | |
53 void ResetMixedStatus(); | |
54 | |
55 private: | |
56 bool _isMixed; | |
57 }; | |
58 | |
59 class NewAudioConferenceMixerImpl : public NewAudioConferenceMixer { | |
hlundin-webrtc
2016/07/01 12:10:04
Rename file.
aleloi
2016/07/01 14:16:29
Done.
| |
60 public: | |
61 // AudioProcessing only accepts 10 ms frames. | |
62 enum { kProcessPeriodicityInMs = 10 }; | |
63 | |
64 NewAudioConferenceMixerImpl(int id); | |
65 ~NewAudioConferenceMixerImpl(); | |
66 | |
67 // Must be called after ctor. | |
68 bool Init(); | |
69 | |
70 // Module functions | |
71 int64_t TimeUntilNextProcess() override; | |
72 void Process() override; | |
73 | |
74 // NewAudioConferenceMixer functions | |
75 int32_t RegisterMixedStreamCallback( | |
76 AudioMixerOutputReceiver* mixReceiver) override; | |
77 int32_t UnRegisterMixedStreamCallback() override; | |
78 int32_t SetMixabilityStatus(MixerAudioSource* participant, | |
79 bool mixable) override; | |
80 bool MixabilityStatus(const MixerAudioSource& participant) const override; | |
81 int32_t SetMinimumMixingFrequency(Frequency freq) override; | |
82 int32_t SetAnonymousMixabilityStatus(MixerAudioSource* participant, | |
83 bool mixable) override; | |
84 bool AnonymousMixabilityStatus( | |
85 const MixerAudioSource& participant) const override; | |
86 | |
87 private: | |
88 enum { DEFAULT_AUDIO_FRAME_POOLSIZE = 50 }; | |
89 | |
90 // Set/get mix frequency | |
91 int32_t SetOutputFrequency(const Frequency& frequency); | |
92 Frequency OutputFrequency() const; | |
93 | |
94 // Fills mixList with the AudioFrames pointers that should be used when | |
95 // mixing. | |
96 // maxAudioFrameCounter both input and output specifies how many more | |
97 // AudioFrames that are allowed to be mixed. | |
98 // rampOutList contain AudioFrames corresponding to an audio stream that | |
99 // used to be mixed but shouldn't be mixed any longer. These AudioFrames | |
100 // should be ramped out over this AudioFrame to avoid audio discontinuities. | |
101 void UpdateToMix(AudioFrameList* mixList, | |
102 AudioFrameList* rampOutList, | |
103 std::map<int, MixerAudioSource*>* mixParticipantList, | |
104 size_t* maxAudioFrameCounter) const; | |
105 | |
106 // Return the lowest mixing frequency that can be used without having to | |
107 // downsample any audio. | |
108 int32_t GetLowestMixingFrequency() const; | |
109 int32_t GetLowestMixingFrequencyFromList( | |
110 const MixerAudioSourceList& mixList) const; | |
111 | |
112 // Return the AudioFrames that should be mixed anonymously. | |
113 void GetAdditionalAudio(AudioFrameList* additionalFramesList) const; | |
114 | |
115 // Update the NewMixHistory of all MixerAudioSources. mixedParticipantsList | |
116 // should contain a map of MixerAudioSources that have been mixed. | |
117 void UpdateMixedStatus( | |
118 const std::map<int, MixerAudioSource*>& mixedParticipantsList) const; | |
119 | |
120 // Clears audioFrameList and reclaims all memory associated with it. | |
121 void ClearAudioFrameList(AudioFrameList* audioFrameList) const; | |
122 | |
123 // This function returns true if it finds the MixerAudioSource in the | |
124 // specified list of MixerAudioSources. | |
125 bool IsParticipantInList(const MixerAudioSource& participant, | |
126 const MixerAudioSourceList& participantList) const; | |
127 | |
128 // Add/remove the MixerAudioSource to the specified | |
129 // MixerAudioSource list. | |
130 bool AddParticipantToList(MixerAudioSource* participant, | |
131 MixerAudioSourceList* participantList) const; | |
132 bool RemoveParticipantFromList(MixerAudioSource* removeParticipant, | |
133 MixerAudioSourceList* participantList) const; | |
134 | |
135 // Mix the AudioFrames stored in audioFrameList into mixedAudio. | |
136 int32_t MixFromList(AudioFrame* mixedAudio, | |
137 const AudioFrameList& audioFrameList) const; | |
138 | |
139 // Mix the AudioFrames stored in audioFrameList into mixedAudio. No | |
140 // record will be kept of this mix (e.g. the corresponding MixerAudioSources | |
141 // will not be marked as IsMixed() | |
142 int32_t MixAnonomouslyFromList(AudioFrame* mixedAudio, | |
143 const AudioFrameList& audioFrameList) const; | |
144 | |
145 bool LimitMixedAudio(AudioFrame* mixedAudio) const; | |
146 | |
147 std::unique_ptr<CriticalSectionWrapper> _crit; | |
148 std::unique_ptr<CriticalSectionWrapper> _cbCrit; | |
149 | |
150 int32_t _id; | |
151 | |
152 Frequency _minimumMixingFreq; | |
153 | |
154 // Mix result callback | |
155 AudioMixerOutputReceiver* _mixReceiver; | |
156 | |
157 // The current sample frequency and sample size when mixing. | |
158 Frequency _outputFrequency; | |
159 size_t _sampleSize; | |
160 | |
161 // Memory pool to avoid allocating/deallocating AudioFrames | |
162 MemoryPool<AudioFrame>* _audioFramePool; | |
163 | |
164 // List of all participants. Note all lists are disjunct | |
165 MixerAudioSourceList _participantList; // May be mixed. | |
166 // Always mixed, anonomously. | |
167 MixerAudioSourceList _additionalParticipantList; | |
168 | |
169 size_t _numMixedParticipants; | |
170 // Determines if we will use a limiter for clipping protection during | |
171 // mixing. | |
172 bool use_limiter_; | |
173 | |
174 uint32_t _timeStamp; | |
175 | |
176 // Metronome class. | |
177 TimeScheduler _timeScheduler; | |
178 | |
179 // Counter keeping track of concurrent calls to process. | |
180 // Note: should never be higher than 1 or lower than 0. | |
181 int16_t _processCalls; | |
182 | |
183 // Used for inhibiting saturation in mixing. | |
184 std::unique_ptr<AudioProcessing> _limiter; | |
185 }; | |
186 } // namespace webrtc | |
187 | |
188 #endif // WEBRTC_MODULES_AUDIO_MIXER_SOURCE_AUDIO_CONFERENCE_MIXER_IMPL_H_ | |
OLD | NEW |