blob: 42b6212bfe080b381a6d904ba63ff10f111c0b1a [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"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
henrik.lundinf00082d2016-12-05 02:22:12 -080024#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.com470e71d2011-07-07 08:21:25 +000030namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000031class AudioProcessing;
32class ProcessThread;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
34namespace voe {
35
36class ChannelManager;
37class MixedAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
solenbergb63310a2017-09-18 03:04:12 -070039class TransmitMixer {
niklase@google.com470e71d2011-07-07 08:21:25 +000040public:
Fredrik Solenberg4332d092017-10-04 09:53:35 +020041 static int32_t Create(TransmitMixer*& mixer);
niklase@google.com470e71d2011-07-07 08:21:25 +000042
43 static void Destroy(TransmitMixer*& mixer);
44
solenbergfc3a2e32017-09-26 09:35:01 -070045 void SetEngineInformation(ChannelManager* channelManager);
niklase@google.com470e71d2011-07-07 08:21:25 +000046
solenbergfc3a2e32017-09-26 09:35:01 -070047 int32_t SetAudioProcessingModule(AudioProcessing* audioProcessingModule);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pbos@webrtc.org6141e132013-04-09 10:09:10 +000049 int32_t PrepareDemux(const void* audioSamples,
Peter Kastingdce40cf2015-08-24 14:52:23 -070050 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -080051 size_t nChannels,
pbos@webrtc.org92135212013-05-14 08:31:39 +000052 uint32_t samplesPerSec,
53 uint16_t totalDelayMS,
54 int32_t clockDrift,
55 uint16_t currentMicLevel,
56 bool keyPressed);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
henrikaec6fbd22017-03-31 05:43:36 -070058 void ProcessAndEncodeAudio();
niklase@google.com470e71d2011-07-07 08:21:25 +000059
andrew@webrtc.org023cc5a2014-01-11 01:25:53 +000060 // Must be called on the same thread as PrepareDemux().
pbos@webrtc.org6141e132013-04-09 10:09:10 +000061 uint32_t CaptureLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.org6141e132013-04-09 10:09:10 +000063 int32_t StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +000064
solenberg8d73f8c2017-03-08 01:52:20 -080065 // TODO(solenberg): Remove, once AudioMonitor is gone.
pbos@webrtc.org6141e132013-04-09 10:09:10 +000066 int8_t AudioLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000067
solenberg796b8f92017-03-01 17:02:23 -080068 // 'virtual' to allow mocking.
69 virtual int16_t AudioLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
zsteine76bd3a2017-07-14 12:17:49 -070071 // 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.com470e71d2011-07-07 08:21:25 +000079 virtual ~TransmitMixer();
80
solenberg76377c52017-02-21 00:54:31 -080081 // Virtual to allow mocking.
82 virtual void EnableStereoChannelSwapping(bool enable);
andrew@webrtc.org02d71742012-04-24 19:47:00 +000083 bool IsStereoChannelSwappingEnabled();
84
solenbergfc3a2e32017-09-26 09:35:01 -070085 // Virtual to allow mocking.
86 virtual bool typing_noise_detected() const;
87
solenberg76377c52017-02-21 00:54:31 -080088protected:
tommiba08a142017-02-28 08:25:11 -080089 TransmitMixer() = default;
solenberg76377c52017-02-21 00:54:31 -080090
niklase@google.com470e71d2011-07-07 08:21:25 +000091private:
andrew@webrtc.org24120852013-03-02 00:14:46 +000092 // Gets the maximum sample rate and number of channels over all currently
93 // sending codecs.
Peter Kasting69558702016-01-12 16:26:35 -080094 void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels);
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000095
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000096 void GenerateAudioFrame(const int16_t audioSamples[],
Peter Kastingdce40cf2015-08-24 14:52:23 -070097 size_t nSamples,
Peter Kasting69558702016-01-12 16:26:35 -080098 size_t nChannels,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000099 int samplesPerSec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
andrew@webrtc.org75dd2882014-02-11 20:52:30 +0000101 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level,
102 bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
henrik.lundinf00082d2016-12-05 02:22:12 -0800104#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700105 void TypingDetection(bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000106#endif
107
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000108 // uses
solenberg76377c52017-02-21 00:54:31 -0800109 ChannelManager* _channelManagerPtr = nullptr;
110 AudioProcessing* audioproc_ = nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000112 // owns
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 AudioFrame _audioFrame;
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +0000114 PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 voe::AudioLevel _audioLevel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
henrik.lundinf00082d2016-12-05 02:22:12 -0800117#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
solenbergfc3a2e32017-09-26 09:35:01 -0700118 webrtc::TypingDetection typing_detection_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
solenbergfc3a2e32017-09-26 09:35:01 -0700121 rtc::CriticalSection lock_;
122 bool typing_noise_detected_ RTC_GUARDED_BY(lock_) = false;
123
solenberg76377c52017-02-21 00:54:31 -0800124 uint32_t _captureLevel = 0;
solenberg76377c52017-02-21 00:54:31 -0800125 bool stereo_codec_ = false;
126 bool swap_stereo_channels_ = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000128} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000129} // namespace webrtc
braveyao@webrtc.orga7cfa672013-12-24 03:39:10 +0000130
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200131#endif // VOICE_ENGINE_TRANSMIT_MIXER_H_