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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webrtc/modules/include/module_common_types.h" | 22 #include "webrtc/modules/include/module_common_types.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
24 #include "webrtc/voice_engine_configurations.h" | 24 #include "webrtc/voice_engine_configurations.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 | 27 |
28 typedef std::vector<AudioFrame*> AudioFrameList; | 28 typedef std::vector<AudioFrame*> AudioFrameList; |
29 | 29 |
30 class AudioMixerImpl : public AudioMixer { | 30 class AudioMixerImpl : public AudioMixer { |
31 public: | 31 public: |
32 struct SourceStatus { | 32 struct SourceStatusWithFrame { |
33 SourceStatus(Source* audio_source, bool is_mixed, float gain) | 33 SourceStatusWithFrame(Source* audio_source, bool is_mixed, float gain) |
34 : audio_source(audio_source), is_mixed(is_mixed), gain(gain) {} | 34 : audio_source(audio_source), |
| 35 is_mixed(is_mixed), |
| 36 gain(gain), |
| 37 audio_frame() {} |
35 Source* audio_source = nullptr; | 38 Source* audio_source = nullptr; |
36 bool is_mixed = false; | 39 bool is_mixed = false; |
37 float gain = 0.0f; | 40 float gain = 0.0f; |
| 41 |
| 42 // A frame that will be passed to audio_source->GetAudioFrameWithInfo. |
| 43 AudioFrame audio_frame{}; |
38 }; | 44 }; |
39 | 45 |
40 typedef std::vector<SourceStatus> SourceStatusList; | 46 typedef std::vector<std::unique_ptr<SourceStatusWithFrame>> |
| 47 SourceStatusWithFrameList; |
41 | 48 |
42 // AudioProcessing only accepts 10 ms frames. | 49 // AudioProcessing only accepts 10 ms frames. |
43 static const int kFrameDurationInMs = 10; | 50 static const int kFrameDurationInMs = 10; |
44 static const int kMaximumAmountOfMixedAudioSources = 3; | 51 static const int kMaximumAmountOfMixedAudioSources = 3; |
45 static const int kDefaultFrequency = 48000; | 52 static const int kDefaultFrequency = 48000; |
46 | 53 |
47 static rtc::scoped_refptr<AudioMixerImpl> Create(); | 54 static rtc::scoped_refptr<AudioMixerImpl> Create(); |
48 | 55 |
49 ~AudioMixerImpl() override; | 56 ~AudioMixerImpl() override; |
50 | 57 |
(...skipping 19 matching lines...) Expand all Loading... |
70 int OutputFrequency() const; | 77 int OutputFrequency() const; |
71 | 78 |
72 // Compute what audio sources to mix from audio_source_list_. Ramp | 79 // Compute what audio sources to mix from audio_source_list_. Ramp |
73 // in and out. Update mixed status. Mixes up to | 80 // in and out. Update mixed status. Mixes up to |
74 // kMaximumAmountOfMixedAudioSources audio sources. | 81 // kMaximumAmountOfMixedAudioSources audio sources. |
75 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 82 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
76 | 83 |
77 // Add/remove the MixerAudioSource to the specified | 84 // Add/remove the MixerAudioSource to the specified |
78 // MixerAudioSource list. | 85 // MixerAudioSource list. |
79 bool AddAudioSourceToList(Source* audio_source, | 86 bool AddAudioSourceToList(Source* audio_source, |
80 SourceStatusList* audio_source_list) const; | 87 SourceStatusWithFrameList* audio_source_list) const; |
81 bool RemoveAudioSourceFromList(Source* remove_audio_source, | 88 bool RemoveAudioSourceFromList( |
82 SourceStatusList* audio_source_list) const; | 89 Source* remove_audio_source, |
| 90 SourceStatusWithFrameList* audio_source_list) const; |
83 | 91 |
84 bool LimitMixedAudio(AudioFrame* mixed_audio) const; | 92 bool LimitMixedAudio(AudioFrame* mixed_audio) const; |
85 | 93 |
86 | 94 |
87 rtc::CriticalSection crit_; | 95 rtc::CriticalSection crit_; |
88 | 96 |
89 // The current sample frequency and sample size when mixing. | 97 // The current sample frequency and sample size when mixing. |
90 int output_frequency_ ACCESS_ON(&thread_checker_); | 98 int output_frequency_ ACCESS_ON(&thread_checker_); |
91 size_t sample_size_ ACCESS_ON(&thread_checker_); | 99 size_t sample_size_ ACCESS_ON(&thread_checker_); |
92 | 100 |
93 // List of all audio sources. Note all lists are disjunct | 101 // List of all audio sources. Note all lists are disjunct |
94 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. | 102 SourceStatusWithFrameList audio_source_list_ |
| 103 GUARDED_BY(crit_); // May be mixed. |
95 | 104 |
96 // Determines if we will use a limiter for clipping protection during | 105 // Determines if we will use a limiter for clipping protection during |
97 // mixing. | 106 // mixing. |
98 bool use_limiter_ ACCESS_ON(&thread_checker_); | 107 bool use_limiter_ ACCESS_ON(&thread_checker_); |
99 | 108 |
100 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); | 109 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); |
101 | 110 |
102 // Ensures that Mix is called from the same thread. | 111 // Ensures that Mix is called from the same thread. |
103 rtc::ThreadChecker thread_checker_; | 112 rtc::ThreadChecker thread_checker_; |
104 | 113 |
105 // Used for inhibiting saturation in mixing. | 114 // Used for inhibiting saturation in mixing. |
106 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); | 115 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); |
107 | 116 |
108 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); | 117 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); |
109 }; | 118 }; |
110 } // namespace webrtc | 119 } // namespace webrtc |
111 | 120 |
112 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ | 121 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ |
OLD | NEW |