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" |
| 23 | #include "voice_engine/monitor_module.h" |
| 24 | #include "voice_engine/voice_engine_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 26 | #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) |
| 27 | #define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 1 |
| 28 | #else |
| 29 | #define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 0 |
| 30 | #endif |
| 31 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | class AudioProcessing; |
| 34 | class ProcessThread; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
| 36 | namespace voe { |
| 37 | |
| 38 | class ChannelManager; |
| 39 | class MixedAudio; |
| 40 | class Statistics; |
| 41 | |
solenberg | b63310a | 2017-09-18 03:04:12 -0700 | [diff] [blame^] | 42 | class TransmitMixer { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | public: |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 44 | static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
| 46 | static void Destroy(TransmitMixer*& mixer); |
| 47 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 48 | int32_t SetEngineInformation(ProcessThread& processThread, |
| 49 | Statistics& engineStatistics, |
| 50 | ChannelManager& channelManager); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 52 | int32_t SetAudioProcessingModule( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | AudioProcessing* audioProcessingModule); |
| 54 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 55 | int32_t PrepareDemux(const void* audioSamples, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 56 | size_t nSamples, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 57 | size_t nChannels, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 58 | uint32_t samplesPerSec, |
| 59 | uint16_t totalDelayMS, |
| 60 | int32_t clockDrift, |
| 61 | uint16_t currentMicLevel, |
| 62 | bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 64 | void ProcessAndEncodeAudio(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
andrew@webrtc.org | 023cc5a | 2014-01-11 01:25:53 +0000 | [diff] [blame] | 66 | // Must be called on the same thread as PrepareDemux(). |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 67 | uint32_t CaptureLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 69 | int32_t StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
solenberg | 8d73f8c | 2017-03-08 01:52:20 -0800 | [diff] [blame] | 71 | // TODO(solenberg): Remove, once AudioMonitor is gone. |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 72 | int8_t AudioLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 74 | // 'virtual' to allow mocking. |
| 75 | virtual int16_t AudioLevelFullRange() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 77 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 78 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
| 79 | // 'virtual' to allow mocking. |
| 80 | virtual double GetTotalInputEnergy() const; |
| 81 | |
| 82 | // 'virtual' to allow mocking. |
| 83 | virtual double GetTotalInputDuration() const; |
| 84 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 85 | int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
| 87 | virtual ~TransmitMixer(); |
| 88 | |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 89 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
tommi | b1175bb | 2017-02-28 01:16:48 -0800 | [diff] [blame] | 90 | // Periodic callback from the MonitorModule. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | void OnPeriodicProcess(); |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 92 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 94 | // Virtual to allow mocking. |
| 95 | virtual void EnableStereoChannelSwapping(bool enable); |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 96 | bool IsStereoChannelSwappingEnabled(); |
| 97 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 98 | protected: |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 99 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
tommi | b1175bb | 2017-02-28 01:16:48 -0800 | [diff] [blame] | 100 | TransmitMixer() : _monitorModule(this) {} |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 101 | #else |
| 102 | TransmitMixer() = default; |
| 103 | #endif |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 104 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | private: |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 106 | TransmitMixer(uint32_t instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
andrew@webrtc.org | 2412085 | 2013-03-02 00:14:46 +0000 | [diff] [blame] | 108 | // Gets the maximum sample rate and number of channels over all currently |
| 109 | // sending codecs. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 110 | void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 111 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 112 | void GenerateAudioFrame(const int16_t audioSamples[], |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 113 | size_t nSamples, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 114 | size_t nChannels, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 115 | int samplesPerSec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 117 | void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, |
| 118 | bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 120 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
henrikg@webrtc.org | c693704 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 121 | void TypingDetection(bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 124 | // uses |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 125 | Statistics* _engineStatisticsPtr = nullptr; |
| 126 | ChannelManager* _channelManagerPtr = nullptr; |
| 127 | AudioProcessing* audioproc_ = nullptr; |
| 128 | VoiceEngineObserver* _voiceEngineObserverPtr = nullptr; |
| 129 | ProcessThread* _processThreadPtr = nullptr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 131 | // owns |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | AudioFrame _audioFrame; |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 133 | PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | voe::AudioLevel _audioLevel; |
| 135 | // protect file instances and their variables in MixedParticipants() |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 136 | rtc::CriticalSection _critSect; |
| 137 | rtc::CriticalSection _callbackCritSect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
henrik.lundin | f00082d | 2016-12-05 02:22:12 -0800 | [diff] [blame] | 139 | #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
tommi | ba08a14 | 2017-02-28 08:25:11 -0800 | [diff] [blame] | 140 | MonitorModule<TransmitMixer> _monitorModule; |
henrikg@webrtc.org | c693704 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 141 | webrtc::TypingDetection _typingDetection; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 142 | bool _typingNoiseWarningPending = false; |
| 143 | bool _typingNoiseDetected = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 146 | int _instanceId = 0; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 147 | uint32_t _captureLevel = 0; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 148 | bool stereo_codec_ = false; |
| 149 | bool swap_stereo_channels_ = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 151 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | } // namespace webrtc |
braveyao@webrtc.org | a7cfa67 | 2013-12-24 03:39:10 +0000 | [diff] [blame] | 153 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 154 | #endif // VOICE_ENGINE_TRANSMIT_MIXER_H_ |