Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: webrtc/modules/audio_mixer/audio_mixer_impl.h

Issue 2408683002: Cleanup of the mixer interface. (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 14 #include <memory>
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/base/scoped_ref_ptr.h"
17 #include "webrtc/base/thread_annotations.h" 18 #include "webrtc/base/thread_annotations.h"
18 #include "webrtc/base/thread_checker.h" 19 #include "webrtc/base/thread_checker.h"
19 #include "webrtc/modules/audio_mixer/audio_mixer.h" 20 #include "webrtc/modules/audio_mixer/audio_mixer.h"
20 #include "webrtc/modules/audio_processing/include/audio_processing.h" 21 #include "webrtc/modules/audio_processing/include/audio_processing.h"
21 #include "webrtc/modules/include/module_common_types.h" 22 #include "webrtc/modules/include/module_common_types.h"
22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
23 #include "webrtc/voice_engine/level_indicator.h" 24 #include "webrtc/voice_engine/level_indicator.h"
24 #include "webrtc/voice_engine_configurations.h" 25 #include "webrtc/voice_engine_configurations.h"
25 26
26 namespace webrtc { 27 namespace webrtc {
27 28
28 typedef std::vector<AudioFrame*> AudioFrameList; 29 typedef std::vector<AudioFrame*> AudioFrameList;
29 30
30 class AudioMixerImpl : public AudioMixer { 31 class AudioMixerImpl : public AudioMixer {
31 public: 32 public:
32 struct SourceStatus { 33 struct SourceStatus {
33 SourceStatus(Source* audio_source, bool is_mixed, float gain) 34 SourceStatus(Source* audio_source, bool is_mixed, float gain)
34 : audio_source(audio_source), is_mixed(is_mixed), gain(gain) {} 35 : audio_source(audio_source), is_mixed(is_mixed), gain(gain) {}
35 Source* audio_source = nullptr; 36 Source* audio_source = nullptr;
36 bool is_mixed = false; 37 bool is_mixed = false;
37 float gain = 0.0f; 38 float gain = 0.0f;
38 }; 39 };
39 40
40 typedef std::vector<SourceStatus> SourceStatusList; 41 typedef std::vector<SourceStatus> SourceStatusList;
41 42
42 // AudioProcessing only accepts 10 ms frames. 43 // AudioProcessing only accepts 10 ms frames.
43 static const int kFrameDurationInMs = 10; 44 static const int kFrameDurationInMs = 10;
45 static const int kMaximumAmountOfMixedAudioSources = 3;
44 static const int kDefaultFrequency = 48000; 46 static const int kDefaultFrequency = 48000;
45 47
46 static std::unique_ptr<AudioMixerImpl> Create(); 48 static rtc::scoped_refptr<AudioMixerImpl> Create();
47 49
48 ~AudioMixerImpl() override; 50 ~AudioMixerImpl() override;
49 51
50 // AudioMixer functions 52 // AudioMixer functions
51 int32_t SetMixabilityStatus(Source* audio_source, bool mixable) override; 53 bool AddSource(Source* audio_source) override;
52 void Mix(int sample_rate, 54 bool RemoveSource(Source* audio_source) override;
55
56 void Mix(int sample_rate_hz,
53 size_t number_of_channels, 57 size_t number_of_channels,
54 AudioFrame* audio_frame_for_mixing) override; 58 AudioFrame* audio_frame_for_mixing) override;
55 59
56 // Returns true if the source was mixed last round. Returns 60 // Returns true if the source was mixed last round. Returns
57 // false and logs an error if the source was never added to the 61 // false and logs an error if the source was never added to the
58 // mixer. 62 // mixer.
59 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const; 63 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const;
60 64
61 private: 65 protected:
62 explicit AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter); 66 explicit AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter);
63 67
68 private:
64 // Set/get mix frequency 69 // Set/get mix frequency
65 void SetOutputFrequency(int frequency); 70 void SetOutputFrequency(int frequency);
66 int OutputFrequency() const; 71 int OutputFrequency() const;
67 72
68 // Compute what audio sources to mix from audio_source_list_. Ramp 73 // Compute what audio sources to mix from audio_source_list_. Ramp
69 // in and out. Update mixed status. Mixes up to 74 // in and out. Update mixed status. Mixes up to
70 // kMaximumAmountOfMixedAudioSources audio sources. 75 // kMaximumAmountOfMixedAudioSources audio sources.
71 AudioFrameList GetNonAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_); 76 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_);
72
73 77
74 // Add/remove the MixerAudioSource to the specified 78 // Add/remove the MixerAudioSource to the specified
75 // MixerAudioSource list. 79 // MixerAudioSource list.
76 bool AddAudioSourceToList(Source* audio_source, 80 bool AddAudioSourceToList(Source* audio_source,
77 SourceStatusList* audio_source_list) const; 81 SourceStatusList* audio_source_list) const;
78 bool RemoveAudioSourceFromList(Source* remove_audio_source, 82 bool RemoveAudioSourceFromList(Source* remove_audio_source,
79 SourceStatusList* audio_source_list) const; 83 SourceStatusList* audio_source_list) const;
80 84
81 bool LimitMixedAudio(AudioFrame* mixed_audio) const; 85 bool LimitMixedAudio(AudioFrame* mixed_audio) const;
82 86
83 87
84 rtc::CriticalSection crit_; 88 rtc::CriticalSection crit_;
85 89
86 // The current sample frequency and sample size when mixing. 90 // The current sample frequency and sample size when mixing.
87 int output_frequency_ ACCESS_ON(&thread_checker_); 91 int output_frequency_ ACCESS_ON(&thread_checker_);
88 size_t sample_size_ ACCESS_ON(&thread_checker_); 92 size_t sample_size_ ACCESS_ON(&thread_checker_);
89 93
90 // List of all audio sources. Note all lists are disjunct 94 // List of all audio sources. Note all lists are disjunct
91 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. 95 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed.
92 96
93 size_t num_mixed_audio_sources_ GUARDED_BY(crit_);
94 // Determines if we will use a limiter for clipping protection during 97 // Determines if we will use a limiter for clipping protection during
95 // mixing. 98 // mixing.
96 bool use_limiter_ ACCESS_ON(&thread_checker_); 99 bool use_limiter_ ACCESS_ON(&thread_checker_);
97 100
98 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); 101 uint32_t time_stamp_ ACCESS_ON(&thread_checker_);
99 102
100 // Ensures that Mix is called from the same thread. 103 // Ensures that Mix is called from the same thread.
101 rtc::ThreadChecker thread_checker_; 104 rtc::ThreadChecker thread_checker_;
102 105
103 // Used for inhibiting saturation in mixing. 106 // Used for inhibiting saturation in mixing.
104 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); 107 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_);
105 108
106 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); 109 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl);
107 }; 110 };
108 } // namespace webrtc 111 } // namespace webrtc
109 112
110 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ 113 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698