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 | |
| 11 | #ifndef WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H |
| 12 | #define WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H |
| 13 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
andrew@webrtc.org | 28e82bf | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 17 | #include "webrtc/common_audio/resampler/include/push_resampler.h" |
| 18 | #include "webrtc/common_types.h" |
henrikg@webrtc.org | c693704 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/audio_processing/typing_detection.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 20 | #include "webrtc/modules/include/module_common_types.h" |
kwiberg | 9d7eb13 | 2016-08-16 04:08:30 -0700 | [diff] [blame] | 21 | #include "webrtc/modules/utility/include/file_player.h" |
| 22 | #include "webrtc/modules/utility/include/file_recorder.h" |
andrew@webrtc.org | 28e82bf | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 23 | #include "webrtc/voice_engine/include/voe_base.h" |
| 24 | #include "webrtc/voice_engine/level_indicator.h" |
| 25 | #include "webrtc/voice_engine/monitor_module.h" |
| 26 | #include "webrtc/voice_engine/voice_engine_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | class AudioProcessing; |
| 31 | class ProcessThread; |
| 32 | class VoEExternalMedia; |
| 33 | class VoEMediaProcess; |
| 34 | |
| 35 | namespace voe { |
| 36 | |
| 37 | class ChannelManager; |
| 38 | class MixedAudio; |
| 39 | class Statistics; |
| 40 | |
| 41 | class TransmitMixer : public MonitorObserver, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 42 | public FileCallback { |
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 | |
| 64 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 65 | int32_t DemuxAndMix(); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 66 | // Used by the Chrome to pass the recording data to the specific VoE |
| 67 | // channels for demux. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 68 | void DemuxAndMix(const int voe_channels[], size_t number_of_voe_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 70 | int32_t EncodeAndSend(); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 71 | // Used by the Chrome to pass the recording data to the specific VoE |
| 72 | // channels for encoding and sending to the network. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 73 | void EncodeAndSend(const int voe_channels[], size_t number_of_voe_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
andrew@webrtc.org | 023cc5a | 2014-01-11 01:25:53 +0000 | [diff] [blame] | 75 | // Must be called on the same thread as PrepareDemux(). |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 76 | uint32_t CaptureLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 78 | int32_t StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | // VoEExternalMedia |
andrew@webrtc.org | 21ab3ba | 2012-10-19 17:30:56 +0000 | [diff] [blame] | 81 | int RegisterExternalMediaProcessing(VoEMediaProcess* object, |
| 82 | ProcessingTypes type); |
| 83 | int DeRegisterExternalMediaProcessing(ProcessingTypes type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 85 | int GetMixingFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
| 87 | // VoEVolumeControl |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 88 | int SetMute(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | bool Mute() const; |
| 91 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 92 | int8_t AudioLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 94 | int16_t AudioLevelFullRange() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
| 96 | bool IsRecordingCall(); |
| 97 | |
| 98 | bool IsRecordingMic(); |
| 99 | |
| 100 | int StartPlayingFileAsMicrophone(const char* fileName, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 101 | bool loop, |
| 102 | FileFormats format, |
| 103 | int startPosition, |
| 104 | float volumeScaling, |
| 105 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | const CodecInst* codecInst); |
| 107 | |
| 108 | int StartPlayingFileAsMicrophone(InStream* stream, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 109 | FileFormats format, |
| 110 | int startPosition, |
| 111 | float volumeScaling, |
| 112 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | const CodecInst* codecInst); |
| 114 | |
| 115 | int StopPlayingFileAsMicrophone(); |
| 116 | |
| 117 | int IsPlayingFileAsMicrophone() const; |
| 118 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | int StartRecordingMicrophone(const char* fileName, |
| 120 | const CodecInst* codecInst); |
| 121 | |
| 122 | int StartRecordingMicrophone(OutStream* stream, |
| 123 | const CodecInst* codecInst); |
| 124 | |
| 125 | int StopRecordingMicrophone(); |
| 126 | |
| 127 | int StartRecordingCall(const char* fileName, const CodecInst* codecInst); |
| 128 | |
| 129 | int StartRecordingCall(OutStream* stream, const CodecInst* codecInst); |
| 130 | |
| 131 | int StopRecordingCall(); |
| 132 | |
| 133 | void SetMixWithMicStatus(bool mix); |
| 134 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 135 | int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
| 137 | virtual ~TransmitMixer(); |
| 138 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 139 | // MonitorObserver |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | void OnPeriodicProcess(); |
| 141 | |
| 142 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 143 | // FileCallback |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 144 | void PlayNotification(int32_t id, |
| 145 | uint32_t durationMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 147 | void RecordNotification(int32_t id, |
| 148 | uint32_t durationMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 150 | void PlayFileEnded(int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 151 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 152 | void RecordFileEnded(int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 154 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 155 | // Typing detection |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 156 | int TimeSinceLastTyping(int &seconds); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 157 | int SetTypingDetectionParameters(int timeWindow, |
| 158 | int costPerTyping, |
| 159 | int reportingThreshold, |
niklas.enbom@webrtc.org | f6edfef | 2012-05-09 13:16:12 +0000 | [diff] [blame] | 160 | int penaltyDecay, |
| 161 | int typeEventDelay); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 162 | #endif |
| 163 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 164 | void EnableStereoChannelSwapping(bool enable); |
| 165 | bool IsStereoChannelSwappingEnabled(); |
| 166 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | private: |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 168 | TransmitMixer(uint32_t instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
andrew@webrtc.org | 2412085 | 2013-03-02 00:14:46 +0000 | [diff] [blame] | 170 | // Gets the maximum sample rate and number of channels over all currently |
| 171 | // sending codecs. |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 172 | void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 173 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 174 | void GenerateAudioFrame(const int16_t audioSamples[], |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 175 | size_t nSamples, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 176 | size_t nChannels, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 177 | int samplesPerSec); |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 178 | int32_t RecordAudioToFile(uint32_t mixingFrequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 180 | int32_t MixOrReplaceAudioWithFile( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 181 | int mixingFrequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 183 | void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, |
| 184 | bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | |
| 186 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
henrikg@webrtc.org | c693704 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 187 | void TypingDetection(bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | #endif |
| 189 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 190 | // uses |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | Statistics* _engineStatisticsPtr; |
| 192 | ChannelManager* _channelManagerPtr; |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 193 | AudioProcessing* audioproc_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | VoiceEngineObserver* _voiceEngineObserverPtr; |
| 195 | ProcessThread* _processThreadPtr; |
| 196 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 197 | // owns |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | MonitorModule _monitorModule; |
| 199 | AudioFrame _audioFrame; |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 200 | PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 201 | std::unique_ptr<FilePlayer> file_player_; |
| 202 | std::unique_ptr<FileRecorder> file_recorder_; |
| 203 | std::unique_ptr<FileRecorder> file_call_recorder_; |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 204 | int _filePlayerId; |
| 205 | int _fileRecorderId; |
| 206 | int _fileCallRecorderId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | bool _filePlaying; |
| 208 | bool _fileRecording; |
| 209 | bool _fileCallRecording; |
| 210 | voe::AudioLevel _audioLevel; |
| 211 | // protect file instances and their variables in MixedParticipants() |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 212 | rtc::CriticalSection _critSect; |
| 213 | rtc::CriticalSection _callbackCritSect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | |
| 215 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
henrikg@webrtc.org | c693704 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 216 | webrtc::TypingDetection _typingDetection; |
jiayl@webrtc.org | bf00740 | 2013-09-17 18:09:20 +0000 | [diff] [blame] | 217 | bool _typingNoiseWarningPending; |
| 218 | bool _typingNoiseDetected; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 219 | #endif |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 220 | bool _saturationWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 222 | int _instanceId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | bool _mixFileWithMicrophone; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 224 | uint32_t _captureLevel; |
andrew@webrtc.org | 21ab3ba | 2012-10-19 17:30:56 +0000 | [diff] [blame] | 225 | VoEMediaProcess* external_postproc_ptr_; |
| 226 | VoEMediaProcess* external_preproc_ptr_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | bool _mute; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 228 | bool stereo_codec_; |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 229 | bool swap_stereo_channels_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 232 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 233 | |
| 234 | } // namespace webrtc |
braveyao@webrtc.org | a7cfa67 | 2013-12-24 03:39:10 +0000 | [diff] [blame] | 235 | |
braveyao@webrtc.org | 0062a6d | 2013-12-24 03:58:51 +0000 | [diff] [blame] | 236 | #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H |