niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VOICE_ENGINE_TRANSMIT_MIXER_H_ |
| 12 | #define VOICE_ENGINE_TRANSMIT_MIXER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "common_audio/resampler/include/push_resampler.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 17 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_processing/typing_detection.h" |
| 19 | #include "modules/include/module_common_types.h" |
| 20 | #include "rtc_base/criticalsection.h" |
| 21 | #include "voice_engine/audio_level.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "voice_engine/include/voe_base.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 24 | #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) |
| 25 | #define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 1 |
| 26 | #else |
| 27 | #define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 0 |
| 28 | #endif |
| 29 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | class AudioProcessing; |
| 32 | class ProcessThread; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
| 34 | namespace voe { |
| 35 | |
| 36 | class ChannelManager; |
| 37 | class MixedAudio; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
solenberg | b63310a | 2017-09-18 03:04:12 -0700 | [diff] [blame] | 39 | class TransmitMixer { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | public: |
Fredrik Solenberg | 4332d09 | 2017-10-04 09:53:35 +0200 | [diff] [blame] | 41 | static int32_t Create(TransmitMixer*& mixer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
| 43 | static void Destroy(TransmitMixer*& mixer); |
| 44 | |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 45 | void SetEngineInformation(ChannelManager* channelManager); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 47 | int32_t SetAudioProcessingModule(AudioProcessing* audioProcessingModule); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 49 | int32_t PrepareDemux(const void* audioSamples, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 50 | size_t nSamples, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 51 | size_t nChannels, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 52 | uint32_t samplesPerSec, |
| 53 | uint16_t totalDelayMS, |
| 54 | int32_t clockDrift, |
| 55 | uint16_t currentMicLevel, |
| 56 | bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 58 | void ProcessAndEncodeAudio(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
andrew@webrtc.org | 023cc5a | 2014-01-11 01:25:53 +0000 | [diff] [blame] | 60 | // Must be called on the same thread as PrepareDemux(). |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 61 | uint32_t CaptureLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 63 | int32_t StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
solenberg | 8d73f8c | 2017-03-08 01:52:20 -0800 | [diff] [blame] | 65 | // TODO(solenberg): Remove, once AudioMonitor is gone. |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 66 | int8_t AudioLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 68 | // 'virtual' to allow mocking. |
| 69 | virtual int16_t AudioLevelFullRange() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 71 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 72 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
| 73 | // 'virtual' to allow mocking. |
| 74 | virtual double GetTotalInputEnergy() const; |
| 75 | |
| 76 | // 'virtual' to allow mocking. |
| 77 | virtual double GetTotalInputDuration() const; |
| 78 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | virtual ~TransmitMixer(); |
| 80 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 81 | // Virtual to allow mocking. |
| 82 | virtual void EnableStereoChannelSwapping(bool enable); |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 83 | bool IsStereoChannelSwappingEnabled(); |
| 84 | |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 85 | // Virtual to allow mocking. |
| 86 | virtual bool typing_noise_detected() const; |
| 87 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 88 | protected: |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 89 | TransmitMixer() = default; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 90 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | private: |
andrew@webrtc.org | 2412085 | 2013-03-02 00:14:46 +0000 | [diff] [blame] | 92 | // Gets the maximum sample rate and number of channels over all currently |
| 93 | // sending codecs. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 94 | void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 95 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 96 | void GenerateAudioFrame(const int16_t audioSamples[], |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 97 | size_t nSamples, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 98 | size_t nChannels, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 99 | int samplesPerSec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 101 | void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, |
| 102 | bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 104 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 105 | void TypingDetection(bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 108 | // uses |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 109 | ChannelManager* _channelManagerPtr = nullptr; |
| 110 | AudioProcessing* audioproc_ = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 112 | // owns |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | AudioFrame _audioFrame; |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 114 | PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | voe::AudioLevel _audioLevel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 117 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 118 | webrtc::TypingDetection typing_detection_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 121 | rtc::CriticalSection lock_; |
| 122 | bool typing_noise_detected_ RTC_GUARDED_BY(lock_) = false; |
| 123 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 124 | uint32_t _captureLevel = 0; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 125 | bool stereo_codec_ = false; |
| 126 | bool swap_stereo_channels_ = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 128 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | } // namespace webrtc |
braveyao@webrtc.org | a7cfa67 | 2013-12-24 03:39:10 +0000 | [diff] [blame] | 130 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 131 | #endif // VOICE_ENGINE_TRANSMIT_MIXER_H_ |