| 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_checker.h" | 19 #include "webrtc/base/thread_checker.h" |
| 19 #include "webrtc/engine_configurations.h" | 20 #include "webrtc/engine_configurations.h" |
| 20 #include "webrtc/modules/audio_mixer/audio_mixer.h" | 21 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
| 22 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" |
| 23 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 21 #include "webrtc/modules/include/module_common_types.h" | 24 #include "webrtc/modules/include/module_common_types.h" |
| 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 22 #include "webrtc/voice_engine/level_indicator.h" | 26 #include "webrtc/voice_engine/level_indicator.h" |
| 23 | 27 |
| 24 namespace webrtc { | 28 namespace webrtc { |
| 25 class AudioProcessing; | |
| 26 class CriticalSectionWrapper; | |
| 27 | 29 |
| 28 typedef std::vector<AudioFrame*> AudioFrameList; | 30 typedef std::vector<AudioFrame*> AudioFrameList; |
| 29 typedef std::vector<MixerAudioSource*> MixerAudioSourceList; | 31 typedef std::vector<MixerAudioSource*> MixerAudioSourceList; |
| 30 | 32 |
| 31 // Cheshire cat implementation of MixerAudioSource's non virtual functions. | |
| 32 class NewMixHistory { | |
| 33 public: | |
| 34 NewMixHistory(); | |
| 35 ~NewMixHistory(); | |
| 36 | |
| 37 // Returns true if the audio source is being mixed. | |
| 38 bool IsMixed() const; | |
| 39 | |
| 40 // Returns true if the audio source was mixed previous mix | |
| 41 // iteration. | |
| 42 bool WasMixed() const; | |
| 43 | |
| 44 // Updates the mixed status. | |
| 45 int32_t SetIsMixed(bool mixed); | |
| 46 | |
| 47 void ResetMixedStatus(); | |
| 48 | |
| 49 private: | |
| 50 bool is_mixed_; | |
| 51 }; | |
| 52 | |
| 53 class AudioMixerImpl : public AudioMixer { | 33 class AudioMixerImpl : public AudioMixer { |
| 54 public: | 34 public: |
| 55 // AudioProcessing only accepts 10 ms frames. | 35 // AudioProcessing only accepts 10 ms frames. |
| 56 static const int kFrameDurationInMs = 10; | 36 static const int kFrameDurationInMs = 10; |
| 57 | 37 |
| 58 explicit AudioMixerImpl(int id); | 38 explicit AudioMixerImpl(int id); |
| 59 | 39 |
| 60 ~AudioMixerImpl() override; | 40 ~AudioMixerImpl() override; |
| 61 | 41 |
| 62 // Must be called after ctor. | 42 // Must be called after ctor. |
| 63 bool Init(); | 43 bool Init(); |
| 64 | 44 |
| 65 // AudioMixer functions | 45 // AudioMixer functions |
| 66 int32_t SetMixabilityStatus(MixerAudioSource* audio_source, | 46 int32_t SetMixabilityStatus(MixerAudioSource* audio_source, |
| 67 bool mixable) override; | 47 bool mixable) override; |
| 68 bool MixabilityStatus(const MixerAudioSource& audio_source) const override; | 48 bool MixabilityStatus(const MixerAudioSource& audio_source) const override; |
| 69 int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source, | 49 int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source, |
| 70 bool mixable) override; | 50 bool mixable) override; |
| 71 void Mix(int sample_rate, | 51 void Mix(int sample_rate, |
| 72 size_t number_of_channels, | 52 int number_of_channels, |
| 73 AudioFrame* audio_frame_for_mixing) override; | 53 AudioFrame* audio_frame_for_mixing) override; |
| 74 bool AnonymousMixabilityStatus( | 54 bool AnonymousMixabilityStatus( |
| 75 const MixerAudioSource& audio_source) const override; | 55 const MixerAudioSource& audio_source) const override; |
| 76 | 56 |
| 77 private: | 57 private: |
| 78 // Set/get mix frequency | 58 // Set/get mix frequency |
| 79 int32_t SetOutputFrequency(const Frequency& frequency); | 59 int32_t SetOutputFrequency(const Frequency& frequency); |
| 80 Frequency OutputFrequency() const; | 60 Frequency OutputFrequency() const; |
| 81 | 61 |
| 82 // Compute what audio sources to mix from audio_source_list_. Ramp | 62 // Compute what audio sources to mix from audio_source_list_. Ramp |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 bool IsAudioSourceInList(const MixerAudioSource& audio_source, | 73 bool IsAudioSourceInList(const MixerAudioSource& audio_source, |
| 94 const MixerAudioSourceList& audio_source_list) const; | 74 const MixerAudioSourceList& audio_source_list) const; |
| 95 | 75 |
| 96 // Add/remove the MixerAudioSource to the specified | 76 // Add/remove the MixerAudioSource to the specified |
| 97 // MixerAudioSource list. | 77 // MixerAudioSource list. |
| 98 bool AddAudioSourceToList(MixerAudioSource* audio_source, | 78 bool AddAudioSourceToList(MixerAudioSource* audio_source, |
| 99 MixerAudioSourceList* audio_source_list) const; | 79 MixerAudioSourceList* audio_source_list) const; |
| 100 bool RemoveAudioSourceFromList(MixerAudioSource* remove_audio_source, | 80 bool RemoveAudioSourceFromList(MixerAudioSource* remove_audio_source, |
| 101 MixerAudioSourceList* audio_source_list) const; | 81 MixerAudioSourceList* audio_source_list) const; |
| 102 | 82 |
| 103 // Mix the AudioFrames stored in audioFrameList into mixed_audio. | |
| 104 static int32_t MixFromList(AudioFrame* mixed_audio, | |
| 105 const AudioFrameList& audio_frame_list, | |
| 106 int32_t id, | |
| 107 bool use_limiter); | |
| 108 | |
| 109 bool LimitMixedAudio(AudioFrame* mixed_audio) const; | 83 bool LimitMixedAudio(AudioFrame* mixed_audio) const; |
| 110 | 84 |
| 111 // Output level functions for VoEVolumeControl. | 85 // Output level functions for VoEVolumeControl. |
| 112 int GetOutputAudioLevel() override; | 86 int GetOutputAudioLevel() override; |
| 113 | 87 |
| 114 int GetOutputAudioLevelFullRange() override; | 88 int GetOutputAudioLevelFullRange() override; |
| 115 | 89 |
| 116 std::unique_ptr<CriticalSectionWrapper> crit_; | 90 std::unique_ptr<CriticalSectionWrapper> crit_; |
| 117 | 91 |
| 118 const int32_t id_; | 92 const int32_t id_; |
| 119 | 93 |
| 120 // The current sample frequency and sample size when mixing. | 94 // The current sample frequency and sample size when mixing. |
| 121 Frequency output_frequency_ ACCESS_ON(&thread_checker_); | 95 Frequency output_frequency_ ACCESS_ON(&thread_checker_); |
| 122 size_t sample_size_ ACCESS_ON(&thread_checker_); | 96 size_t sample_size_ ACCESS_ON(&thread_checker_); |
| 123 | 97 |
| 124 // List of all audio sources. Note all lists are disjunct | 98 // List of all audio sources. Note all lists are disjunct |
| 125 MixerAudioSourceList audio_source_list_ GUARDED_BY(crit_); // May be mixed. | 99 MixerAudioSourceList audio_source_list_ GUARDED_BY(crit_); // May be mixed. |
| 126 | 100 |
| 127 // Always mixed, anonymously. | 101 // Always mixed, anonymously. |
| 128 MixerAudioSourceList additional_audio_source_list_ GUARDED_BY(crit_); | 102 MixerAudioSourceList additional_audio_source_list_ GUARDED_BY(crit_); |
| 129 | 103 |
| 130 size_t num_mixed_audio_sources_ GUARDED_BY(crit_); | 104 int num_mixed_audio_sources_ GUARDED_BY(crit_); |
| 131 // Determines if we will use a limiter for clipping protection during | 105 // Determines if we will use a limiter for clipping protection during |
| 132 // mixing. | 106 // mixing. |
| 133 bool use_limiter_ ACCESS_ON(&thread_checker_); | 107 bool use_limiter_ ACCESS_ON(&thread_checker_); |
| 134 | 108 |
| 135 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); | 109 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); |
| 136 | 110 |
| 137 // Ensures that Mix is called from the same thread. | 111 // Ensures that Mix is called from the same thread. |
| 138 rtc::ThreadChecker thread_checker_; | 112 rtc::ThreadChecker thread_checker_; |
| 139 | 113 |
| 140 // Used for inhibiting saturation in mixing. | 114 // Used for inhibiting saturation in mixing. |
| 141 std::unique_ptr<AudioProcessing> limiter_; | 115 std::unique_ptr<AudioProcessing> limiter_; |
| 142 | 116 |
| 143 // Measures audio level for the combined signal. | 117 // Measures audio level for the combined signal. |
| 144 voe::AudioLevel audio_level_ ACCESS_ON(&thread_checker_); | 118 voe::AudioLevel audio_level_ ACCESS_ON(&thread_checker_); |
| 145 | 119 |
| 146 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); | 120 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); |
| 147 }; | 121 }; |
| 148 } // namespace webrtc | 122 } // namespace webrtc |
| 149 | 123 |
| 150 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ | 124 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ |
| OLD | NEW |