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

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

Issue 2408683002: Cleanup of the mixer interface. (Closed)
Patch Set: 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/thread_annotations.h" 17 #include "webrtc/base/thread_annotations.h"
18 #include "webrtc/base/thread_checker.h" 18 #include "webrtc/base/thread_checker.h"
19 #include "webrtc/base/scoped_ref_ptr.h"
the sun 2016/10/10 13:35:49 nit: s comes before t in western european alphabet
aleloi 2016/10/10 14:02:27 Done.
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; 38 float gain = 0;
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();
aleloi 2016/10/10 13:06:31 When we move the interface to webrtc/api, we can a
the sun 2016/10/10 13:35:49 It's ok to do it separately. Once you get around t
aleloi 2016/10/10 14:02:27 Acknowledged.
49
50 explicit AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter);
aleloi 2016/10/10 13:06:31 A refcounted object must have a public constructor
the sun 2016/10/10 13:35:49 No, protected should be enough if you're using rtc
aleloi 2016/10/10 14:02:27 Done.
47 51
48 ~AudioMixerImpl() override; 52 ~AudioMixerImpl() override;
49 53
50 // AudioMixer functions 54 // AudioMixer functions
51 int32_t SetMixabilityStatus(Source* audio_source, bool mixable) override; 55 bool AddSource(Source* audio_source) override;
52 void Mix(int sample_rate, 56 bool RemoveSource(Source* audio_source) override;
57
58 void Mix(int sample_rate_hz,
53 size_t number_of_channels, 59 size_t number_of_channels,
54 AudioFrame* audio_frame_for_mixing) override; 60 AudioFrame* audio_frame_for_mixing) override;
55 61
56 // Returns true if the source was mixed last round. Returns 62 // Returns true if the source was mixed last round. Returns
57 // false and logs an error if the source was never added to the 63 // false and logs an error if the source was never added to the
58 // mixer. 64 // mixer.
59 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const; 65 bool GetAudioSourceMixabilityStatusForTest(Source* audio_source) const;
60 66
61 private: 67 private:
62 explicit AudioMixerImpl(std::unique_ptr<AudioProcessing> limiter);
63
64 // Set/get mix frequency 68 // Set/get mix frequency
65 void SetOutputFrequency(int frequency); 69 void SetOutputFrequency(int frequency);
66 int OutputFrequency() const; 70 int OutputFrequency() const;
67 71
68 // Compute what audio sources to mix from audio_source_list_. Ramp 72 // Compute what audio sources to mix from audio_source_list_. Ramp
69 // in and out. Update mixed status. Mixes up to 73 // in and out. Update mixed status. Mixes up to
70 // kMaximumAmountOfMixedAudioSources audio sources. 74 // kMaximumAmountOfMixedAudioSources audio sources.
71 AudioFrameList GetNonAnonymousAudio() EXCLUSIVE_LOCKS_REQUIRED(crit_); 75 AudioFrameList GetAudioFromSources() EXCLUSIVE_LOCKS_REQUIRED(crit_);
72
73 76
74 // Add/remove the MixerAudioSource to the specified 77 // Add/remove the MixerAudioSource to the specified
75 // MixerAudioSource list. 78 // MixerAudioSource list.
76 bool AddAudioSourceToList(Source* audio_source, 79 bool AddAudioSourceToList(Source* audio_source,
77 SourceStatusList* audio_source_list) const; 80 SourceStatusList* audio_source_list) const;
78 bool RemoveAudioSourceFromList(Source* remove_audio_source, 81 bool RemoveAudioSourceFromList(Source* remove_audio_source,
79 SourceStatusList* audio_source_list) const; 82 SourceStatusList* audio_source_list) const;
80 83
81 bool LimitMixedAudio(AudioFrame* mixed_audio) const; 84 bool LimitMixedAudio(AudioFrame* mixed_audio) const;
82 85
83 86
84 rtc::CriticalSection crit_; 87 rtc::CriticalSection crit_;
85 88
86 // The current sample frequency and sample size when mixing. 89 // The current sample frequency and sample size when mixing.
87 int output_frequency_ ACCESS_ON(&thread_checker_); 90 int output_frequency_ ACCESS_ON(&thread_checker_);
88 size_t sample_size_ ACCESS_ON(&thread_checker_); 91 size_t sample_size_ ACCESS_ON(&thread_checker_);
89 92
90 // List of all audio sources. Note all lists are disjunct 93 // List of all audio sources. Note all lists are disjunct
91 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed. 94 SourceStatusList audio_source_list_ GUARDED_BY(crit_); // May be mixed.
92 95
93 size_t num_mixed_audio_sources_ GUARDED_BY(crit_);
94 // Determines if we will use a limiter for clipping protection during 96 // Determines if we will use a limiter for clipping protection during
95 // mixing. 97 // mixing.
96 bool use_limiter_ ACCESS_ON(&thread_checker_); 98 bool use_limiter_ ACCESS_ON(&thread_checker_);
97 99
98 uint32_t time_stamp_ ACCESS_ON(&thread_checker_); 100 uint32_t time_stamp_ ACCESS_ON(&thread_checker_);
99 101
100 // Ensures that Mix is called from the same thread. 102 // Ensures that Mix is called from the same thread.
101 rtc::ThreadChecker thread_checker_; 103 rtc::ThreadChecker thread_checker_;
102 104
103 // Used for inhibiting saturation in mixing. 105 // Used for inhibiting saturation in mixing.
104 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_); 106 std::unique_ptr<AudioProcessing> limiter_ ACCESS_ON(&thread_checker_);
105 107
106 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl); 108 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixerImpl);
107 }; 109 };
108 } // namespace webrtc 110 } // namespace webrtc
109 111
110 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_ 112 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698