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 | |
andrew@webrtc.org | 28e82bf | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 14 | #include "webrtc/common_audio/resampler/include/push_resampler.h" |
| 15 | #include "webrtc/common_types.h" |
| 16 | #include "webrtc/modules/interface/module_common_types.h" |
| 17 | #include "webrtc/modules/utility/interface/file_player.h" |
| 18 | #include "webrtc/modules/utility/interface/file_recorder.h" |
| 19 | #include "webrtc/voice_engine/include/voe_base.h" |
| 20 | #include "webrtc/voice_engine/level_indicator.h" |
| 21 | #include "webrtc/voice_engine/monitor_module.h" |
| 22 | #include "webrtc/voice_engine/voice_engine_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class AudioProcessing; |
| 27 | class ProcessThread; |
| 28 | class VoEExternalMedia; |
| 29 | class VoEMediaProcess; |
| 30 | |
| 31 | namespace voe { |
| 32 | |
| 33 | class ChannelManager; |
| 34 | class MixedAudio; |
| 35 | class Statistics; |
| 36 | |
| 37 | class TransmitMixer : public MonitorObserver, |
| 38 | public FileCallback |
| 39 | |
| 40 | { |
| 41 | public: |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 42 | static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | static void Destroy(TransmitMixer*& mixer); |
| 45 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 46 | int32_t SetEngineInformation(ProcessThread& processThread, |
| 47 | Statistics& engineStatistics, |
| 48 | ChannelManager& channelManager); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 50 | int32_t SetAudioProcessingModule( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | AudioProcessing* audioProcessingModule); |
| 52 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 53 | int32_t PrepareDemux(const void* audioSamples, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 54 | uint32_t nSamples, |
| 55 | uint8_t nChannels, |
| 56 | uint32_t samplesPerSec, |
| 57 | uint16_t totalDelayMS, |
| 58 | int32_t clockDrift, |
| 59 | uint16_t currentMicLevel, |
| 60 | bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
| 62 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 63 | int32_t DemuxAndMix(); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame^] | 64 | // Used by the Chrome to pass the recording data to the specific VoE |
| 65 | // channels for demux. |
| 66 | void DemuxAndMix(int voe_channels[], int number_of_voe_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 68 | int32_t EncodeAndSend(); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame^] | 69 | // Used by the Chrome to pass the recording data to the specific VoE |
| 70 | // channels for encoding and sending to the network. |
| 71 | void EncodeAndSend(int voe_channels[], int number_of_voe_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 73 | uint32_t CaptureLevel() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 75 | int32_t StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | // VoEDtmf |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 78 | void UpdateMuteMicrophoneTime(uint32_t lengthMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
| 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 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 119 | int ScaleFileAsMicrophonePlayout(float scale); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
| 121 | int StartRecordingMicrophone(const char* fileName, |
| 122 | const CodecInst* codecInst); |
| 123 | |
| 124 | int StartRecordingMicrophone(OutStream* stream, |
| 125 | const CodecInst* codecInst); |
| 126 | |
| 127 | int StopRecordingMicrophone(); |
| 128 | |
| 129 | int StartRecordingCall(const char* fileName, const CodecInst* codecInst); |
| 130 | |
| 131 | int StartRecordingCall(OutStream* stream, const CodecInst* codecInst); |
| 132 | |
| 133 | int StopRecordingCall(); |
| 134 | |
| 135 | void SetMixWithMicStatus(bool mix); |
| 136 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 137 | int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
| 139 | virtual ~TransmitMixer(); |
| 140 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 141 | // MonitorObserver |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | void OnPeriodicProcess(); |
| 143 | |
| 144 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 145 | // FileCallback |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 146 | void PlayNotification(int32_t id, |
| 147 | uint32_t durationMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 149 | void RecordNotification(int32_t id, |
| 150 | uint32_t durationMs); |
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 PlayFileEnded(int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 154 | void RecordFileEnded(int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 156 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 157 | // Typing detection |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 158 | int TimeSinceLastTyping(int &seconds); |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 159 | int SetTypingDetectionParameters(int timeWindow, |
| 160 | int costPerTyping, |
| 161 | int reportingThreshold, |
niklas.enbom@webrtc.org | f6edfef | 2012-05-09 13:16:12 +0000 | [diff] [blame] | 162 | int penaltyDecay, |
| 163 | int typeEventDelay); |
niklas.enbom@webrtc.org | 3dc8865 | 2012-03-30 09:53:54 +0000 | [diff] [blame] | 164 | #endif |
| 165 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 166 | void EnableStereoChannelSwapping(bool enable); |
| 167 | bool IsStereoChannelSwappingEnabled(); |
| 168 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | private: |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 170 | TransmitMixer(uint32_t instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | |
andrew@webrtc.org | 2412085 | 2013-03-02 00:14:46 +0000 | [diff] [blame] | 172 | // Gets the maximum sample rate and number of channels over all currently |
| 173 | // sending codecs. |
| 174 | void GetSendCodecInfo(int* max_sample_rate, int* max_channels); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 175 | |
| 176 | int GenerateAudioFrame(const int16_t audioSamples[], |
| 177 | int nSamples, |
| 178 | int nChannels, |
| 179 | int samplesPerSec); |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 180 | int32_t RecordAudioToFile(uint32_t mixingFrequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 182 | int32_t MixOrReplaceAudioWithFile( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 183 | int mixingFrequency); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 185 | void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
| 187 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 188 | int TypingDetection(bool keyPressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | #endif |
| 190 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 191 | // uses |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | Statistics* _engineStatisticsPtr; |
| 193 | ChannelManager* _channelManagerPtr; |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 194 | AudioProcessing* audioproc_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | VoiceEngineObserver* _voiceEngineObserverPtr; |
| 196 | ProcessThread* _processThreadPtr; |
| 197 | |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 198 | // owns |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | MonitorModule _monitorModule; |
| 200 | AudioFrame _audioFrame; |
andrew@webrtc.org | 28e82bf | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 201 | PushResampler resampler_; // ADM sample rate -> mixing rate |
andrew@webrtc.org | 21ab3ba | 2012-10-19 17:30:56 +0000 | [diff] [blame] | 202 | FilePlayer* _filePlayerPtr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | FileRecorder* _fileRecorderPtr; |
| 204 | FileRecorder* _fileCallRecorderPtr; |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 205 | int _filePlayerId; |
| 206 | int _fileRecorderId; |
| 207 | int _fileCallRecorderId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | bool _filePlaying; |
| 209 | bool _fileRecording; |
| 210 | bool _fileCallRecording; |
| 211 | voe::AudioLevel _audioLevel; |
| 212 | // protect file instances and their variables in MixedParticipants() |
| 213 | CriticalSectionWrapper& _critSect; |
| 214 | CriticalSectionWrapper& _callbackCritSect; |
| 215 | |
| 216 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 217 | int32_t _timeActive; |
| 218 | int32_t _timeSinceLastTyping; |
| 219 | int32_t _penaltyCounter; |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 220 | bool _typingNoiseWarning; |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 221 | |
| 222 | // Tunable treshold values |
| 223 | int _timeWindow; // nr of10ms slots accepted to count as a hit. |
| 224 | int _costPerTyping; // Penalty added for a typing + activity coincide. |
| 225 | int _reportingThreshold; // Threshold for _penaltyCounter. |
| 226 | int _penaltyDecay; // How much we reduce _penaltyCounter every 10 ms. |
niklas.enbom@webrtc.org | f6edfef | 2012-05-09 13:16:12 +0000 | [diff] [blame] | 227 | int _typeEventDelay; // How old typing events we allow |
niklas.enbom@webrtc.org | 06e722a | 2012-04-04 07:44:27 +0000 | [diff] [blame] | 228 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | #endif |
andrew@webrtc.org | 6be1e93 | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 230 | bool _saturationWarning; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 232 | int _instanceId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 233 | bool _mixFileWithMicrophone; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 234 | uint32_t _captureLevel; |
andrew@webrtc.org | 21ab3ba | 2012-10-19 17:30:56 +0000 | [diff] [blame] | 235 | VoEMediaProcess* external_postproc_ptr_; |
| 236 | VoEMediaProcess* external_preproc_ptr_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | bool _mute; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 238 | int32_t _remainingMuteMicTimeMs; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 239 | bool stereo_codec_; |
andrew@webrtc.org | 02d7174 | 2012-04-24 19:47:00 +0000 | [diff] [blame] | 240 | bool swap_stereo_channels_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H |
| 244 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 245 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 246 | |
| 247 | } // namespace webrtc |