blob: f26359553784f71010b521f7d07473d899216275 [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;
39class Statistics;
40
solenbergb63310a2017-09-18 03:04:12 -070041class TransmitMixer {
niklase@google.com470e71d2011-07-07 08:21:25 +000042public:
pbos@webrtc.org92135212013-05-14 08:31:39 +000043 static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45 static void Destroy(TransmitMixer*& mixer);
46
solenbergfc3a2e32017-09-26 09:35:01 -070047 void SetEngineInformation(ChannelManager* channelManager);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
solenbergfc3a2e32017-09-26 09:35:01 -070049 int32_t SetAudioProcessingModule(AudioProcessing* audioProcessingModule);
niklase@google.com470e71d2011-07-07 08:21:25 +000050
pbos@webrtc.org6141e132013-04-09 10:09:10 +000051 int32_t PrepareDemux(const void* audioSamples,
Peter Kastingdce40cf2015-08-24 14:52:23 -070052 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -080053 size_t nChannels,
pbos@webrtc.org92135212013-05-14 08:31:39 +000054 uint32_t samplesPerSec,
55 uint16_t totalDelayMS,
56 int32_t clockDrift,
57 uint16_t currentMicLevel,
58 bool keyPressed);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
henrikaec6fbd22017-03-31 05:43:36 -070060 void ProcessAndEncodeAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000061
andrew@webrtc.org023cc5a2014-01-11 01:25:53 +000062 // Must be called on the same thread as PrepareDemux().
pbos@webrtc.org6141e132013-04-09 10:09:10 +000063 uint32_t CaptureLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
pbos@webrtc.org6141e132013-04-09 10:09:10 +000065 int32_t StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +000066
solenberg8d73f8c2017-03-08 01:52:20 -080067 // TODO(solenberg): Remove, once AudioMonitor is gone.
pbos@webrtc.org6141e132013-04-09 10:09:10 +000068 int8_t AudioLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
solenberg796b8f92017-03-01 17:02:23 -080070 // 'virtual' to allow mocking.
71 virtual int16_t AudioLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
zsteine76bd3a2017-07-14 12:17:49 -070073 // See description of "totalAudioEnergy" in the WebRTC stats spec:
74 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
75 // 'virtual' to allow mocking.
76 virtual double GetTotalInputEnergy() const;
77
78 // 'virtual' to allow mocking.
79 virtual double GetTotalInputDuration() const;
80
niklase@google.com470e71d2011-07-07 08:21:25 +000081 virtual ~TransmitMixer();
82
solenberg76377c52017-02-21 00:54:31 -080083 // Virtual to allow mocking.
84 virtual void EnableStereoChannelSwapping(bool enable);
andrew@webrtc.org02d71742012-04-24 19:47:00 +000085 bool IsStereoChannelSwappingEnabled();
86
solenbergfc3a2e32017-09-26 09:35:01 -070087 // Virtual to allow mocking.
88 virtual bool typing_noise_detected() const;
89
solenberg76377c52017-02-21 00:54:31 -080090protected:
tommiba08a142017-02-28 08:25:11 -080091 TransmitMixer() = default;
solenberg76377c52017-02-21 00:54:31 -080092
niklase@google.com470e71d2011-07-07 08:21:25 +000093private:
pbos@webrtc.org92135212013-05-14 08:31:39 +000094 TransmitMixer(uint32_t instanceId);
niklase@google.com470e71d2011-07-07 08:21:25 +000095
andrew@webrtc.org24120852013-03-02 00:14:46 +000096 // Gets the maximum sample rate and number of channels over all currently
97 // sending codecs.
Peter Kasting69558702016-01-12 16:26:35 -080098 void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels);
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000099
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000100 void GenerateAudioFrame(const int16_t audioSamples[],
Peter Kastingdce40cf2015-08-24 14:52:23 -0700101 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -0800102 size_t nChannels,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +0000103 int samplesPerSec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000105 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level,
106 bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
henrik.lundinf00082d2016-12-05 02:22:12 -0800108#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700109 void TypingDetection(bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000110#endif
111
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000112 // uses
solenberg76377c52017-02-21 00:54:31 -0800113 ChannelManager* _channelManagerPtr = nullptr;
114 AudioProcessing* audioproc_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000116 // owns
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 AudioFrame _audioFrame;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000118 PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 voe::AudioLevel _audioLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
henrik.lundinf00082d2016-12-05 02:22:12 -0800121#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700122 webrtc::TypingDetection typing_detection_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
solenbergfc3a2e32017-09-26 09:35:01 -0700125 rtc::CriticalSection lock_;
126 bool typing_noise_detected_ RTC_GUARDED_BY(lock_) = false;
127
solenberg76377c52017-02-21 00:54:31 -0800128 int _instanceId = 0;
solenberg76377c52017-02-21 00:54:31 -0800129 uint32_t _captureLevel = 0;
solenberg76377c52017-02-21 00:54:31 -0800130 bool stereo_codec_ = false;
131 bool swap_stereo_channels_ = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000133} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000134} // namespace webrtc
braveyao@webrtc.orga7cfa672013-12-24 03:39:10 +0000135
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200136#endif // VOICE_ENGINE_TRANSMIT_MIXER_H_