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

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

Issue 2396483002: Made MixerAudioSource a pure 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 <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/gtest_prod_util.h"
18 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
19 #include "webrtc/base/thread_checker.h" 20 #include "webrtc/base/thread_checker.h"
20 #include "webrtc/engine_configurations.h" 21 #include "webrtc/engine_configurations.h"
21 #include "webrtc/modules/audio_mixer/audio_mixer.h" 22 #include "webrtc/modules/audio_mixer/audio_mixer.h"
22 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" 23 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
24 #include "webrtc/modules/audio_mixer/audio_source_with_mix_status.h"
23 #include "webrtc/modules/audio_processing/include/audio_processing.h" 25 #include "webrtc/modules/audio_processing/include/audio_processing.h"
24 #include "webrtc/modules/include/module_common_types.h" 26 #include "webrtc/modules/include/module_common_types.h"
25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 27 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
26 #include "webrtc/voice_engine/level_indicator.h" 28 #include "webrtc/voice_engine/level_indicator.h"
27 29
28 namespace webrtc { 30 namespace webrtc {
29 31
30 typedef std::vector<AudioFrame*> AudioFrameList; 32 typedef std::vector<AudioFrame*> AudioFrameList;
31 typedef std::vector<MixerAudioSource*> MixerAudioSourceList; 33 typedef std::vector<AudioSourceWithMixStatus> MixerAudioSourceList;
32 34
33 class AudioMixerImpl : public AudioMixer { 35 class AudioMixerImpl : public AudioMixer {
34 public: 36 public:
35 // AudioProcessing only accepts 10 ms frames. 37 // AudioProcessing only accepts 10 ms frames.
36 static const int kFrameDurationInMs = 10; 38 static const int kFrameDurationInMs = 10;
37 39
38 static std::unique_ptr<AudioMixer> Create(int id); 40 static std::unique_ptr<AudioMixerImpl> Create(int id);
ivoc 2016/10/04 20:39:29 Don't you need the old Create function as well?
aleloi 2016/10/05 15:18:19 There are two Create functions defined in the impl
39 41
40 ~AudioMixerImpl() override; 42 ~AudioMixerImpl() override;
41 43
42 // AudioMixer functions 44 // AudioMixer functions
43 int32_t SetMixabilityStatus(MixerAudioSource* audio_source, 45 int32_t SetMixabilityStatus(MixerAudioSource* audio_source,
44 bool mixable) override; 46 bool mixable) override;
45 bool MixabilityStatus(const MixerAudioSource& audio_source) const override; 47 bool MixabilityStatus(const MixerAudioSource& audio_source) const override;
46 int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source, 48 int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source,
47 bool mixable) override; 49 bool mixable) override;
48 void Mix(int sample_rate, 50 void Mix(int sample_rate,
49 size_t number_of_channels, 51 size_t number_of_channels,
50 AudioFrame* audio_frame_for_mixing) override; 52 AudioFrame* audio_frame_for_mixing) override;
51 bool AnonymousMixabilityStatus( 53 bool AnonymousMixabilityStatus(
52 const MixerAudioSource& audio_source) const override; 54 const MixerAudioSource& audio_source) const override;
53 55
56 // Returns true if the participant was mixed last round. Returns
57 // false and logs an error if the participant was never added to the
58 // mixer.
59 bool GetAudioSourceMixabilityStatus(MixerAudioSource* participant);
the sun 2016/10/04 20:36:10 Source or participant? Make thy mind up! :)
aleloi 2016/10/05 15:18:19 Done.
60
54 private: 61 private:
55 AudioMixerImpl(int id, std::unique_ptr<AudioProcessing> limiter); 62 AudioMixerImpl(int id, std::unique_ptr<AudioProcessing> limiter);
56 63
57 // Set/get mix frequency 64 // Set/get mix frequency
58 int32_t SetOutputFrequency(const Frequency& frequency); 65 int32_t SetOutputFrequency(const Frequency& frequency);
59 Frequency OutputFrequency() const; 66 Frequency OutputFrequency() const;
60 67
61 // Compute what audio sources to mix from audio_source_list_. Ramp 68 // Compute what audio sources to mix from audio_source_list_. Ramp
62 // in and out. Update mixed status. Mixes up to 69 // in and out. Update mixed status. Mixes up to
63 // kMaximumAmountOfMixedAudioSources audio sources. 70 // kMaximumAmountOfMixedAudioSources audio sources.
64 AudioFrameList GetNonAnonymousAudio() const EXCLUSIVE_LOCKS_REQUIRED(crit_); 71 AudioFrameList GetNonAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_);
65 72
66 // Return the AudioFrames that should be mixed anonymously. Ramp in 73 // Return the AudioFrames that should be mixed anonymously. Ramp in
67 // and out. Update mixed status. 74 // and out. Update mixed status.
68 AudioFrameList GetAnonymousAudio() const EXCLUSIVE_LOCKS_REQUIRED(crit_); 75 AudioFrameList GetAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_);
69 76
70 // This function returns true if it finds the MixerAudioSource in the 77 // This function returns true if it finds the MixerAudioSource in the
71 // specified list of MixerAudioSources. 78 // specified list of MixerAudioSources.
72 bool IsAudioSourceInList(const MixerAudioSource& audio_source, 79 bool IsAudioSourceInList(const MixerAudioSource& audio_source,
73 const MixerAudioSourceList& audio_source_list) const; 80 const MixerAudioSourceList& audio_source_list) const;
74 81
75 // Add/remove the MixerAudioSource to the specified 82 // Add/remove the MixerAudioSource to the specified
76 // MixerAudioSource list. 83 // MixerAudioSource list.
77 bool AddAudioSourceToList(MixerAudioSource* audio_source, 84 bool AddAudioSourceToList(MixerAudioSource* audio_source,
78 MixerAudioSourceList* audio_source_list) const; 85 MixerAudioSourceList* audio_source_list) const;
79 bool RemoveAudioSourceFromList(MixerAudioSource* remove_audio_source, 86 bool RemoveAudioSourceFromList(MixerAudioSource* remove_audio_source,
80 MixerAudioSourceList* audio_source_list) const; 87 MixerAudioSourceList* audio_source_list) const;
81 88
82 bool LimitMixedAudio(AudioFrame* mixed_audio) const; 89 bool LimitMixedAudio(AudioFrame* mixed_audio) const;
83 90
84 // Output level functions for VoEVolumeControl. 91 // Output level functions for VoEVolumeControl.
85 int GetOutputAudioLevel() override; 92 int GetOutputAudioLevel() override;
86 93
87 int GetOutputAudioLevelFullRange() override; 94 int GetOutputAudioLevelFullRange() override;
88 95
96 // Searches for the AudioSourceWithMixStatus object corresponding to
97 // an audio source. If the audio source was never added with
98 // Set*MixabilityStatus, this returns nullptr.
99 AudioSourceWithMixStatus* GetSourceWithStatus(MixerAudioSource* audio_source);
100
89 rtc::CriticalSection crit_; 101 rtc::CriticalSection crit_;
90 102
91 const int32_t id_; 103 const int32_t id_;
92 104
93 // The current sample frequency and sample size when mixing. 105 // The current sample frequency and sample size when mixing.
94 Frequency output_frequency_ ACCESS_ON(&thread_checker_); 106 Frequency output_frequency_ ACCESS_ON(&thread_checker_);
95 size_t sample_size_ ACCESS_ON(&thread_checker_); 107 size_t sample_size_ ACCESS_ON(&thread_checker_);
96 108
97 // List of all audio sources. Note all lists are disjunct 109 // List of all audio sources. Note all lists are disjunct
98 MixerAudioSourceList audio_source_list_ GUARDED_BY(crit_); // May be mixed. 110 MixerAudioSourceList audio_source_list_ GUARDED_BY(crit_); // May be mixed.
(...skipping 11 matching lines...) Expand all
110 // Ensures that Mix is called from the same thread. 122 // Ensures that Mix is called from the same thread.
111 rtc::ThreadChecker thread_checker_; 123 rtc::ThreadChecker thread_checker_;
112 124
113 // Used for inhibiting saturation in mixing. 125 // Used for inhibiting saturation in mixing.
114 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); 126 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_);
115 127
116 // Measures audio level for the combined signal. 128 // Measures audio level for the combined signal.
117 voe::AudioLevel audio_level_ ACCESS_ON(&thread_checker_); 129 voe::AudioLevel audio_level_ ACCESS_ON(&thread_checker_);
118 130
119 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); 131 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl);
132 FRIEND_TEST_ALL_PREFIXES(AudioMixerTest, Create);
the sun 2016/10/04 20:36:10 Can we test without creating a circular relationsh
aleloi 2016/10/05 15:18:19 MixerImpl::Create is public now. When we split the
the sun 2016/10/05 19:32:11 I don't understand. Why can't we make the test dep
aleloi 2016/10/06 09:26:12 That was confusing, sorry. We can depend only on t
120 }; 133 };
121 } // namespace webrtc 134 } // namespace webrtc
122 135
123 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ 136 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698