aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 1 | /* |
aleloi | 5d167d6 | 2016-08-24 02:20:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
aleloi | 201dfe9 | 2016-10-20 05:06:39 -0700 | [diff] [blame] | 11 | #ifndef WEBRTC_API_AUDIO_AUDIO_MIXER_H_ |
| 12 | #define WEBRTC_API_AUDIO_AUDIO_MIXER_H_ |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 13 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
aleloi | 116ec6d | 2016-10-12 06:07:07 -0700 | [diff] [blame] | 16 | #include "webrtc/base/refcount.h" |
aleloi | 5d167d6 | 2016-08-24 02:20:54 -0700 | [diff] [blame] | 17 | #include "webrtc/modules/include/module_common_types.h" |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
aleloi | 201dfe9 | 2016-10-20 05:06:39 -0700 | [diff] [blame] | 21 | // WORK IN PROGRESS |
| 22 | // This class is under development and is not yet intended for for use outside |
| 23 | // of WebRtc/Libjingle. |
aleloi | 116ec6d | 2016-10-12 06:07:07 -0700 | [diff] [blame] | 24 | class AudioMixer : public rtc::RefCountInterface { |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 25 | public: |
aleloi | e891415 | 2016-10-11 06:18:31 -0700 | [diff] [blame] | 26 | // A callback class that all mixer participants must inherit from/implement. |
| 27 | class Source { |
| 28 | public: |
| 29 | enum class AudioFrameInfo { |
| 30 | kNormal, // The samples in audio_frame are valid and should be used. |
aleloi | 201dfe9 | 2016-10-20 05:06:39 -0700 | [diff] [blame] | 31 | kMuted, // The samples in audio_frame should not be used, but |
| 32 | // should be implicitly interpreted as zero. Other |
| 33 | // fields in audio_frame may be read and should |
| 34 | // contain meaningful values. |
| 35 | kError, // The audio_frame will not be used. |
aleloi | e891415 | 2016-10-11 06:18:31 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
aleloi | 6c27849 | 2016-10-20 14:24:39 -0700 | [diff] [blame] | 38 | // Overwrites |audio_frame|. The data_ field is overwritten with |
| 39 | // 10 ms of new audio (either 1 or 2 interleaved channels) at |
| 40 | // |sample_rate_hz|. All fields in |audio_frame| must be updated. |
| 41 | virtual AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, |
| 42 | AudioFrame* audio_frame) = 0; |
aleloi | e891415 | 2016-10-11 06:18:31 -0700 | [diff] [blame] | 43 | |
aleloi | 201dfe9 | 2016-10-20 05:06:39 -0700 | [diff] [blame] | 44 | // A way for a mixer implementation to distinguish participants. |
| 45 | virtual int Ssrc() = 0; |
aleloi | 116ec6d | 2016-10-12 06:07:07 -0700 | [diff] [blame] | 46 | |
aleloi | e891415 | 2016-10-11 06:18:31 -0700 | [diff] [blame] | 47 | virtual ~Source() {} |
| 48 | }; |
| 49 | |
aleloi | 116ec6d | 2016-10-12 06:07:07 -0700 | [diff] [blame] | 50 | // Returns true if adding/removing was successful. A source is never |
| 51 | // added twice and removal is never attempted if a source has not |
| 52 | // been successfully added to the mixer. Addition and removal can |
| 53 | // happen on different threads. |
| 54 | virtual bool AddSource(Source* audio_source) = 0; |
| 55 | virtual bool RemoveSource(Source* audio_source) = 0; |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 56 | |
aleloi | 5d167d6 | 2016-08-24 02:20:54 -0700 | [diff] [blame] | 57 | // Performs mixing by asking registered audio sources for audio. The |
aleloi | 6c27849 | 2016-10-20 14:24:39 -0700 | [diff] [blame] | 58 | // mixed result is placed in the provided AudioFrame. This method |
| 59 | // will only be called from a single thread. The rate and channels |
| 60 | // arguments specify the rate and number of channels of the mix |
| 61 | // result. All fields in |audio_frame_for_mixing| must be updated. |
aleloi | e97974d | 2016-10-12 03:06:09 -0700 | [diff] [blame] | 62 | virtual void Mix(int sample_rate_hz, |
aleloi | 5d167d6 | 2016-08-24 02:20:54 -0700 | [diff] [blame] | 63 | size_t number_of_channels, |
| 64 | AudioFrame* audio_frame_for_mixing) = 0; |
aleloi | 6c27849 | 2016-10-20 14:24:39 -0700 | [diff] [blame] | 65 | |
| 66 | protected: |
| 67 | // Since the mixer is reference counted, the destructor may be |
| 68 | // called from any thread. |
| 69 | ~AudioMixer() override {} |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 70 | }; |
aleloi | 77ad394 | 2016-07-04 06:33:02 -0700 | [diff] [blame] | 71 | } // namespace webrtc |
| 72 | |
aleloi | 201dfe9 | 2016-10-20 05:06:39 -0700 | [diff] [blame] | 73 | #endif // WEBRTC_API_AUDIO_AUDIO_MIXER_H_ |