blob: 6cfe0704d3325c00994e4d81fed3fce7ad61c647 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VOICE_ENGINE_TRANSMIT_MIXER_H_
12#define VOICE_ENGINE_TRANSMIT_MIXER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
kwiberg5a25d952016-08-17 07:31:12 -070014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "common_audio/resampler/include/push_resampler.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020017#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#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 Bonadei92ea95e2017-09-15 06:47:31 +020022#include "voice_engine/include/voe_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "voice_engine/voice_engine_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
henrik.lundinf00082d2016-12-05 02:22:12 -080025#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
26#define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 1
27#else
28#define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 0
29#endif
30
niklase@google.com470e71d2011-07-07 08:21:25 +000031namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000032class AudioProcessing;
33class ProcessThread;
niklase@google.com470e71d2011-07-07 08:21:25 +000034
35namespace voe {
36
37class ChannelManager;
38class MixedAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
solenbergb63310a2017-09-18 03:04:12 -070040class TransmitMixer {
niklase@google.com470e71d2011-07-07 08:21:25 +000041public:
Fredrik Solenberg4332d092017-10-04 09:53:35 +020042 static int32_t Create(TransmitMixer*& mixer);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
44 static void Destroy(TransmitMixer*& mixer);
45
solenbergfc3a2e32017-09-26 09:35:01 -070046 void SetEngineInformation(ChannelManager* channelManager);
niklase@google.com470e71d2011-07-07 08:21:25 +000047
solenbergfc3a2e32017-09-26 09:35:01 -070048 int32_t SetAudioProcessingModule(AudioProcessing* audioProcessingModule);
niklase@google.com470e71d2011-07-07 08:21:25 +000049
pbos@webrtc.org6141e132013-04-09 10:09:10 +000050 int32_t PrepareDemux(const void* audioSamples,
Peter Kastingdce40cf2015-08-24 14:52:23 -070051 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -080052 size_t nChannels,
pbos@webrtc.org92135212013-05-14 08:31:39 +000053 uint32_t samplesPerSec,
54 uint16_t totalDelayMS,
55 int32_t clockDrift,
56 uint16_t currentMicLevel,
57 bool keyPressed);
niklase@google.com470e71d2011-07-07 08:21:25 +000058
henrikaec6fbd22017-03-31 05:43:36 -070059 void ProcessAndEncodeAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000060
andrew@webrtc.org023cc5a2014-01-11 01:25:53 +000061 // Must be called on the same thread as PrepareDemux().
pbos@webrtc.org6141e132013-04-09 10:09:10 +000062 uint32_t CaptureLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
pbos@webrtc.org6141e132013-04-09 10:09:10 +000064 int32_t StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +000065
solenberg8d73f8c2017-03-08 01:52:20 -080066 // TODO(solenberg): Remove, once AudioMonitor is gone.
pbos@webrtc.org6141e132013-04-09 10:09:10 +000067 int8_t AudioLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
solenberg796b8f92017-03-01 17:02:23 -080069 // 'virtual' to allow mocking.
70 virtual int16_t AudioLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
zsteine76bd3a2017-07-14 12:17:49 -070072 // See description of "totalAudioEnergy" in the WebRTC stats spec:
73 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
74 // 'virtual' to allow mocking.
75 virtual double GetTotalInputEnergy() const;
76
77 // 'virtual' to allow mocking.
78 virtual double GetTotalInputDuration() const;
79
niklase@google.com470e71d2011-07-07 08:21:25 +000080 virtual ~TransmitMixer();
81
solenberg76377c52017-02-21 00:54:31 -080082 // Virtual to allow mocking.
83 virtual void EnableStereoChannelSwapping(bool enable);
andrew@webrtc.org02d71742012-04-24 19:47:00 +000084 bool IsStereoChannelSwappingEnabled();
85
solenbergfc3a2e32017-09-26 09:35:01 -070086 // Virtual to allow mocking.
87 virtual bool typing_noise_detected() const;
88
solenberg76377c52017-02-21 00:54:31 -080089protected:
tommiba08a142017-02-28 08:25:11 -080090 TransmitMixer() = default;
solenberg76377c52017-02-21 00:54:31 -080091
niklase@google.com470e71d2011-07-07 08:21:25 +000092private:
andrew@webrtc.org24120852013-03-02 00:14:46 +000093 // Gets the maximum sample rate and number of channels over all currently
94 // sending codecs.
Peter Kasting69558702016-01-12 16:26:35 -080095 void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels);
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000096
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000097 void GenerateAudioFrame(const int16_t audioSamples[],
Peter Kastingdce40cf2015-08-24 14:52:23 -070098 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -080099 size_t nChannels,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000100 int samplesPerSec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000102 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level,
103 bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
henrik.lundinf00082d2016-12-05 02:22:12 -0800105#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700106 void TypingDetection(bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107#endif
108
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000109 // uses
solenberg76377c52017-02-21 00:54:31 -0800110 ChannelManager* _channelManagerPtr = nullptr;
111 AudioProcessing* audioproc_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000113 // owns
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 AudioFrame _audioFrame;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000115 PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 voe::AudioLevel _audioLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
henrik.lundinf00082d2016-12-05 02:22:12 -0800118#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700119 webrtc::TypingDetection typing_detection_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
solenbergfc3a2e32017-09-26 09:35:01 -0700122 rtc::CriticalSection lock_;
123 bool typing_noise_detected_ RTC_GUARDED_BY(lock_) = false;
124
solenberg76377c52017-02-21 00:54:31 -0800125 uint32_t _captureLevel = 0;
solenberg76377c52017-02-21 00:54:31 -0800126 bool stereo_codec_ = false;
127 bool swap_stereo_channels_ = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000129} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000130} // namespace webrtc
braveyao@webrtc.orga7cfa672013-12-24 03:39:10 +0000131
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200132#endif // VOICE_ENGINE_TRANSMIT_MIXER_H_