OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ |
12 #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ | 12 #define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/modules/audio_mixer/audio_mixer_defines.h" | |
17 #include "webrtc/modules/include/module.h" | 16 #include "webrtc/modules/include/module.h" |
18 #include "webrtc/modules/include/module_common_types.h" | 17 #include "webrtc/modules/include/module_common_types.h" |
19 | 18 |
20 namespace webrtc { | 19 namespace webrtc { |
21 | 20 |
22 class AudioMixer { | 21 class AudioMixer { |
23 public: | 22 public: |
24 static const int kMaximumAmountOfMixedAudioSources = 3; | 23 static const int kMaximumAmountOfMixedAudioSources = 3; |
25 enum Frequency { | 24 enum Frequency { |
26 kNbInHz = 8000, | 25 kNbInHz = 8000, |
27 kWbInHz = 16000, | 26 kWbInHz = 16000, |
28 kSwbInHz = 32000, | 27 kSwbInHz = 32000, |
29 kFbInHz = 48000, | 28 kFbInHz = 48000, |
30 kDefaultFrequency = kWbInHz | 29 kDefaultFrequency = kWbInHz |
31 }; | 30 }; |
32 | 31 |
| 32 // A callback class that all mixer participants must inherit from/implement. |
| 33 class Source { |
| 34 public: |
| 35 enum class AudioFrameInfo { |
| 36 kNormal, // The samples in audio_frame are valid and should be used. |
| 37 kMuted, // The samples in audio_frame should not be used, but should be |
| 38 // implicitly interpreted as zero. Other fields in audio_frame |
| 39 // may be read and should contain meaningful values. |
| 40 kError // audio_frame will not be used. |
| 41 }; |
| 42 |
| 43 struct AudioFrameWithInfo { |
| 44 AudioFrame* audio_frame; |
| 45 AudioFrameInfo audio_frame_info; |
| 46 }; |
| 47 |
| 48 // The implementation of GetAudioFrameWithInfo should update |
| 49 // audio_frame with new audio every time it's called. Implementing |
| 50 // classes are allowed to return the same AudioFrame pointer on |
| 51 // different calls. The pointer must stay valid until the next |
| 52 // mixing call or until this audio source is disconnected from the |
| 53 // mixer. The mixer may modify the contents of the passed |
| 54 // AudioFrame pointer at any time until the next call to |
| 55 // GetAudioFrameWithInfo, or until the source is removed from the |
| 56 // mixer. |
| 57 virtual AudioFrameWithInfo GetAudioFrameWithInfo(int32_t id, |
| 58 int sample_rate_hz) = 0; |
| 59 |
| 60 protected: |
| 61 virtual ~Source() {} |
| 62 }; |
| 63 |
33 // Factory method. Constructor disabled. | 64 // Factory method. Constructor disabled. |
34 static std::unique_ptr<AudioMixer> Create(int id); | 65 static std::unique_ptr<AudioMixer> Create(int id); |
35 virtual ~AudioMixer() {} | 66 virtual ~AudioMixer() {} |
36 | 67 |
37 // Add/remove audio sources as candidates for mixing. | 68 // Add/remove audio sources as candidates for mixing. |
38 virtual int32_t SetMixabilityStatus(MixerAudioSource* audio_source, | 69 virtual int32_t SetMixabilityStatus(Source* audio_source, bool mixable) = 0; |
39 bool mixable) = 0; | |
40 // Returns true if an audio source is a candidate for mixing. | 70 // Returns true if an audio source is a candidate for mixing. |
41 virtual bool MixabilityStatus(const MixerAudioSource& audio_source) const = 0; | 71 virtual bool MixabilityStatus(const Source& audio_source) const = 0; |
42 | 72 |
43 // Inform the mixer that the audio source should always be mixed and not | 73 // Inform the mixer that the audio source should always be mixed and not |
44 // count toward the number of mixed audio sources. Note that an audio source | 74 // count toward the number of mixed audio sources. Note that an audio source |
45 // must have been added to the mixer (by calling SetMixabilityStatus()) | 75 // must have been added to the mixer (by calling SetMixabilityStatus()) |
46 // before this function can be successfully called. | 76 // before this function can be successfully called. |
47 virtual int32_t SetAnonymousMixabilityStatus(MixerAudioSource* audio_source, | 77 virtual int32_t SetAnonymousMixabilityStatus(Source* audio_source, |
48 bool mixable) = 0; | 78 bool mixable) = 0; |
49 | 79 |
50 // Performs mixing by asking registered audio sources for audio. The | 80 // Performs mixing by asking registered audio sources for audio. The |
51 // mixed result is placed in the provided AudioFrame. Can only be | 81 // mixed result is placed in the provided AudioFrame. Can only be |
52 // called from a single thread. The rate and channels arguments | 82 // called from a single thread. The rate and channels arguments |
53 // specify the rate and number of channels of the mix result. | 83 // specify the rate and number of channels of the mix result. |
54 virtual void Mix(int sample_rate, | 84 virtual void Mix(int sample_rate, |
55 size_t number_of_channels, | 85 size_t number_of_channels, |
56 AudioFrame* audio_frame_for_mixing) = 0; | 86 AudioFrame* audio_frame_for_mixing) = 0; |
57 | 87 |
58 // Returns true if the audio source is mixed anonymously. | 88 // Returns true if the audio source is mixed anonymously. |
59 virtual bool AnonymousMixabilityStatus( | 89 virtual bool AnonymousMixabilityStatus(const Source& audio_source) const = 0; |
60 const MixerAudioSource& audio_source) const = 0; | |
61 | 90 |
62 // Output level functions for VoEVolumeControl. Return value | 91 // Output level functions for VoEVolumeControl. Return value |
63 // between 0 and 9 is returned by voe::AudioLevel. | 92 // between 0 and 9 is returned by voe::AudioLevel. |
64 virtual int GetOutputAudioLevel() = 0; | 93 virtual int GetOutputAudioLevel() = 0; |
65 | 94 |
66 // Return value between 0 and 0x7fff is returned by voe::AudioLevel. | 95 // Return value between 0 and 0x7fff is returned by voe::AudioLevel. |
67 virtual int GetOutputAudioLevelFullRange() = 0; | 96 virtual int GetOutputAudioLevelFullRange() = 0; |
68 | 97 |
69 protected: | 98 protected: |
70 AudioMixer() {} | 99 AudioMixer() {} |
71 | 100 |
72 private: | 101 private: |
73 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixer); | 102 RTC_DISALLOW_COPY_AND_ASSIGN(AudioMixer); |
74 }; | 103 }; |
75 } // namespace webrtc | 104 } // namespace webrtc |
76 | 105 |
77 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ | 106 #endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_H_ |
OLD | NEW |