2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
12 #define WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
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"
26 class AudioProcessing;
28 class VoEExternalMedia;
29 class VoEMediaProcess;
37 class TransmitMixer : public MonitorObserver,
42 static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId);
44 static void Destroy(TransmitMixer*& mixer);
46 int32_t SetEngineInformation(ProcessThread& processThread,
47 Statistics& engineStatistics,
48 ChannelManager& channelManager);
50 int32_t SetAudioProcessingModule(
51 AudioProcessing* audioProcessingModule);
53 int32_t PrepareDemux(const void* audioSamples,
56 uint32_t samplesPerSec,
57 uint16_t totalDelayMS,
59 uint16_t currentMicLevel,
63 int32_t DemuxAndMix();
64 // Used by the Chrome to pass the recording data to the specific VoE
65 // channels for demux.
66 void DemuxAndMix(const int voe_channels[], int number_of_voe_channels);
68 int32_t EncodeAndSend();
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(const int voe_channels[], int number_of_voe_channels);
73 // Must be called on the same thread as PrepareDemux().
74 uint32_t CaptureLevel() const;
79 void UpdateMuteMicrophoneTime(uint32_t lengthMs);
82 int RegisterExternalMediaProcessing(VoEMediaProcess* object,
83 ProcessingTypes type);
84 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
86 int GetMixingFrequency();
89 int SetMute(bool enable);
93 int8_t AudioLevel() const;
95 int16_t AudioLevelFullRange() const;
97 bool IsRecordingCall();
99 bool IsRecordingMic();
101 int StartPlayingFileAsMicrophone(const char* fileName,
107 const CodecInst* codecInst);
109 int StartPlayingFileAsMicrophone(InStream* stream,
114 const CodecInst* codecInst);
116 int StopPlayingFileAsMicrophone();
118 int IsPlayingFileAsMicrophone() const;
120 int ScaleFileAsMicrophonePlayout(float scale);
122 int StartRecordingMicrophone(const char* fileName,
123 const CodecInst* codecInst);
125 int StartRecordingMicrophone(OutStream* stream,
126 const CodecInst* codecInst);
128 int StopRecordingMicrophone();
130 int StartRecordingCall(const char* fileName, const CodecInst* codecInst);
132 int StartRecordingCall(OutStream* stream, const CodecInst* codecInst);
134 int StopRecordingCall();
136 void SetMixWithMicStatus(bool mix);
138 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
140 virtual ~TransmitMixer();
143 void OnPeriodicProcess();
147 void PlayNotification(int32_t id,
148 uint32_t durationMs);
150 void RecordNotification(int32_t id,
151 uint32_t durationMs);
153 void PlayFileEnded(int32_t id);
155 void RecordFileEnded(int32_t id);
157 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
159 int TimeSinceLastTyping(int &seconds);
160 int SetTypingDetectionParameters(int timeWindow,
162 int reportingThreshold,
167 void EnableStereoChannelSwapping(bool enable);
168 bool IsStereoChannelSwappingEnabled();
171 TransmitMixer(uint32_t instanceId);
173 // Gets the maximum sample rate and number of channels over all currently
175 void GetSendCodecInfo(int* max_sample_rate, int* max_channels);
177 int GenerateAudioFrame(const int16_t audioSamples[],
181 int32_t RecordAudioToFile(uint32_t mixingFrequency);
183 int32_t MixOrReplaceAudioWithFile(
184 int mixingFrequency);
186 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level);
188 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
189 int TypingDetection(bool keyPressed);
193 Statistics* _engineStatisticsPtr;
194 ChannelManager* _channelManagerPtr;
195 AudioProcessing* audioproc_;
196 VoiceEngineObserver* _voiceEngineObserverPtr;
197 ProcessThread* _processThreadPtr;
200 MonitorModule _monitorModule;
201 AudioFrame _audioFrame;
202 PushResampler resampler_; // ADM sample rate -> mixing rate
203 FilePlayer* _filePlayerPtr;
204 FileRecorder* _fileRecorderPtr;
205 FileRecorder* _fileCallRecorderPtr;
208 int _fileCallRecorderId;
211 bool _fileCallRecording;
212 voe::AudioLevel _audioLevel;
213 // protect file instances and their variables in MixedParticipants()
214 CriticalSectionWrapper& _critSect;
215 CriticalSectionWrapper& _callbackCritSect;
217 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
219 int32_t _timeSinceLastTyping;
220 int32_t _penaltyCounter;
221 bool _typingNoiseWarningPending;
222 bool _typingNoiseDetected;
224 // Tunable treshold values
225 int _timeWindow; // nr of10ms slots accepted to count as a hit.
226 int _costPerTyping; // Penalty added for a typing + activity coincide.
227 int _reportingThreshold; // Threshold for _penaltyCounter.
228 int _penaltyDecay; // How much we reduce _penaltyCounter every 10 ms.
229 int _typeEventDelay; // How old typing events we allow
232 bool _saturationWarning;
235 bool _mixFileWithMicrophone;
236 uint32_t _captureLevel;
237 VoEMediaProcess* external_postproc_ptr_;
238 VoEMediaProcess* external_preproc_ptr_;
240 int32_t _remainingMuteMicTimeMs;
242 bool swap_stereo_channels_;
247 } // namespace webrtc
249 #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H