andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | 4a68e95 | 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" |
henrikg@webrtc.org | c13a537 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/audio_processing/typing_detection.h" |
andrew@webrtc.org | 4a68e95 | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/interface/module_common_types.h" |
| 18 | #include "webrtc/modules/utility/interface/file_player.h" |
| 19 | #include "webrtc/modules/utility/interface/file_recorder.h" |
andrew@webrtc.org | f7c73b5 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
andrew@webrtc.org | 4a68e95 | 2013-05-02 00:30:36 +0000 | [diff] [blame] | 21 | #include "webrtc/voice_engine/include/voe_base.h" |
| 22 | #include "webrtc/voice_engine/level_indicator.h" |
| 23 | #include "webrtc/voice_engine/monitor_module.h" |
| 24 | #include "webrtc/voice_engine/voice_engine_defines.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | class AudioProcessing; |
| 29 | class ProcessThread; |
| 30 | class VoEExternalMedia; |
| 31 | class VoEMediaProcess; |
| 32 | |
| 33 | namespace voe { |
| 34 | |
| 35 | class ChannelManager; |
| 36 | class MixedAudio; |
| 37 | class Statistics; |
| 38 | |
| 39 | class TransmitMixer : public MonitorObserver, |
andrew@webrtc.org | f7c73b5 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 40 | public FileCallback { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 41 | public: |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 42 | static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 43 | |
| 44 | static void Destroy(TransmitMixer*& mixer); |
| 45 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 46 | int32_t SetEngineInformation(ProcessThread& processThread, |
| 47 | Statistics& engineStatistics, |
| 48 | ChannelManager& channelManager); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 49 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 50 | int32_t SetAudioProcessingModule( |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 51 | AudioProcessing* audioProcessingModule); |
| 52 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 53 | int32_t PrepareDemux(const void* audioSamples, |
pbos@webrtc.org | ca7a9a2 | 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); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 61 | |
| 62 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 63 | int32_t DemuxAndMix(); |
xians@webrtc.org | 44f1239 | 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. |
xians@webrtc.org | 0e6fa8c | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 66 | void DemuxAndMix(const int voe_channels[], int number_of_voe_channels); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 67 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 68 | int32_t EncodeAndSend(); |
xians@webrtc.org | 44f1239 | 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. |
xians@webrtc.org | 0e6fa8c | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 71 | void EncodeAndSend(const int voe_channels[], int number_of_voe_channels); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 72 | |
andrew@webrtc.org | 22470b5 | 2014-01-11 01:25:53 +0000 | [diff] [blame] | 73 | // Must be called on the same thread as PrepareDemux(). |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 74 | uint32_t CaptureLevel() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 75 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 76 | int32_t StopSend(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 77 | |
| 78 | // VoEDtmf |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 79 | void UpdateMuteMicrophoneTime(uint32_t lengthMs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 80 | |
| 81 | // VoEExternalMedia |
| 82 | int RegisterExternalMediaProcessing(VoEMediaProcess* object, |
| 83 | ProcessingTypes type); |
| 84 | int DeRegisterExternalMediaProcessing(ProcessingTypes type); |
| 85 | |
| 86 | int GetMixingFrequency(); |
| 87 | |
| 88 | // VoEVolumeControl |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 89 | int SetMute(bool enable); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 90 | |
| 91 | bool Mute() const; |
| 92 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 93 | int8_t AudioLevel() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 95 | int16_t AudioLevelFullRange() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 96 | |
| 97 | bool IsRecordingCall(); |
| 98 | |
| 99 | bool IsRecordingMic(); |
| 100 | |
| 101 | int StartPlayingFileAsMicrophone(const char* fileName, |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 102 | bool loop, |
| 103 | FileFormats format, |
| 104 | int startPosition, |
| 105 | float volumeScaling, |
| 106 | int stopPosition, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 107 | const CodecInst* codecInst); |
| 108 | |
| 109 | int StartPlayingFileAsMicrophone(InStream* stream, |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 110 | FileFormats format, |
| 111 | int startPosition, |
| 112 | float volumeScaling, |
| 113 | int stopPosition, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 114 | const CodecInst* codecInst); |
| 115 | |
| 116 | int StopPlayingFileAsMicrophone(); |
| 117 | |
| 118 | int IsPlayingFileAsMicrophone() const; |
| 119 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 120 | int StartRecordingMicrophone(const char* fileName, |
| 121 | const CodecInst* codecInst); |
| 122 | |
| 123 | int StartRecordingMicrophone(OutStream* stream, |
| 124 | const CodecInst* codecInst); |
| 125 | |
| 126 | int StopRecordingMicrophone(); |
| 127 | |
| 128 | int StartRecordingCall(const char* fileName, const CodecInst* codecInst); |
| 129 | |
| 130 | int StartRecordingCall(OutStream* stream, const CodecInst* codecInst); |
| 131 | |
| 132 | int StopRecordingCall(); |
| 133 | |
| 134 | void SetMixWithMicStatus(bool mix); |
| 135 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 136 | int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 137 | |
| 138 | virtual ~TransmitMixer(); |
| 139 | |
| 140 | // MonitorObserver |
| 141 | void OnPeriodicProcess(); |
| 142 | |
| 143 | |
| 144 | // FileCallback |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 145 | void PlayNotification(int32_t id, |
| 146 | uint32_t durationMs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 147 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 148 | void RecordNotification(int32_t id, |
| 149 | uint32_t durationMs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 150 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 151 | void PlayFileEnded(int32_t id); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 152 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 153 | void RecordFileEnded(int32_t id); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 154 | |
| 155 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
| 156 | // Typing detection |
| 157 | int TimeSinceLastTyping(int &seconds); |
| 158 | int SetTypingDetectionParameters(int timeWindow, |
| 159 | int costPerTyping, |
| 160 | int reportingThreshold, |
| 161 | int penaltyDecay, |
| 162 | int typeEventDelay); |
| 163 | #endif |
| 164 | |
| 165 | void EnableStereoChannelSwapping(bool enable); |
| 166 | bool IsStereoChannelSwappingEnabled(); |
| 167 | |
| 168 | private: |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 169 | TransmitMixer(uint32_t instanceId); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 170 | |
andrew@webrtc.org | 4de0a10 | 2013-03-02 00:14:46 +0000 | [diff] [blame] | 171 | // Gets the maximum sample rate and number of channels over all currently |
| 172 | // sending codecs. |
| 173 | void GetSendCodecInfo(int* max_sample_rate, int* max_channels); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 174 | |
andrew@webrtc.org | f7c73b5 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 175 | void GenerateAudioFrame(const int16_t audioSamples[], |
| 176 | int nSamples, |
| 177 | int nChannels, |
| 178 | int samplesPerSec); |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 179 | int32_t RecordAudioToFile(uint32_t mixingFrequency); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 180 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 181 | int32_t MixOrReplaceAudioWithFile( |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 182 | int mixingFrequency); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 183 | |
andrew@webrtc.org | 22c954a | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 184 | void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, |
| 185 | bool key_pressed); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 186 | |
| 187 | #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION |
henrikg@webrtc.org | c13a537 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 188 | void TypingDetection(bool keyPressed); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 189 | #endif |
| 190 | |
| 191 | // uses |
| 192 | Statistics* _engineStatisticsPtr; |
| 193 | ChannelManager* _channelManagerPtr; |
andrew@webrtc.org | b563e5e | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 194 | AudioProcessing* audioproc_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 195 | VoiceEngineObserver* _voiceEngineObserverPtr; |
| 196 | ProcessThread* _processThreadPtr; |
| 197 | |
| 198 | // owns |
| 199 | MonitorModule _monitorModule; |
| 200 | AudioFrame _audioFrame; |
andrew@webrtc.org | 708ff4d | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 201 | PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 202 | FilePlayer* _filePlayerPtr; |
| 203 | FileRecorder* _fileRecorderPtr; |
| 204 | FileRecorder* _fileCallRecorderPtr; |
| 205 | int _filePlayerId; |
| 206 | int _fileRecorderId; |
| 207 | int _fileCallRecorderId; |
| 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 |
henrikg@webrtc.org | c13a537 | 2014-01-30 09:50:46 +0000 | [diff] [blame] | 217 | webrtc::TypingDetection _typingDetection; |
jiayl@webrtc.org | 39e22a1 | 2013-09-17 18:09:20 +0000 | [diff] [blame] | 218 | bool _typingNoiseWarningPending; |
| 219 | bool _typingNoiseDetected; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 220 | #endif |
andrew@webrtc.org | b563e5e | 2013-03-01 18:47:28 +0000 | [diff] [blame] | 221 | bool _saturationWarning; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 222 | |
| 223 | int _instanceId; |
| 224 | bool _mixFileWithMicrophone; |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 225 | uint32_t _captureLevel; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 226 | VoEMediaProcess* external_postproc_ptr_; |
| 227 | VoEMediaProcess* external_preproc_ptr_; |
| 228 | bool _mute; |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 229 | int32_t _remainingMuteMicTimeMs; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 230 | bool stereo_codec_; |
| 231 | bool swap_stereo_channels_; |
andrew@webrtc.org | f7c73b5 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 232 | scoped_ptr<int16_t[]> mono_buffer_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 235 | } // namespace voe |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 236 | |
| 237 | } // namespace webrtc |
braveyao@webrtc.org | 5d7992f | 2013-12-24 03:39:10 +0000 | [diff] [blame] | 238 | |
braveyao@webrtc.org | 1a6b274 | 2013-12-24 03:58:51 +0000 | [diff] [blame] | 239 | #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H |