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/audio_processing/typing_detection.h"
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"
20 #include "webrtc/voice_engine/include/voe_base.h"
21 #include "webrtc/voice_engine/level_indicator.h"
22 #include "webrtc/voice_engine/monitor_module.h"
23 #include "webrtc/voice_engine/voice_engine_defines.h"
27 class AudioProcessing;
29 class VoEExternalMedia;
30 class VoEMediaProcess;
38 class TransmitMixer : public MonitorObserver,
43 static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId);
45 static void Destroy(TransmitMixer*& mixer);
47 int32_t SetEngineInformation(ProcessThread& processThread,
48 Statistics& engineStatistics,
49 ChannelManager& channelManager);
51 int32_t SetAudioProcessingModule(
52 AudioProcessing* audioProcessingModule);
54 int32_t PrepareDemux(const void* audioSamples,
57 uint32_t samplesPerSec,
58 uint16_t totalDelayMS,
60 uint16_t currentMicLevel,
64 int32_t DemuxAndMix();
65 // Used by the Chrome to pass the recording data to the specific VoE
66 // channels for demux.
67 void DemuxAndMix(const int voe_channels[], int number_of_voe_channels);
69 int32_t EncodeAndSend();
70 // Used by the Chrome to pass the recording data to the specific VoE
71 // channels for encoding and sending to the network.
72 void EncodeAndSend(const int voe_channels[], int number_of_voe_channels);
74 // Must be called on the same thread as PrepareDemux().
75 uint32_t CaptureLevel() const;
80 void UpdateMuteMicrophoneTime(uint32_t lengthMs);
83 int RegisterExternalMediaProcessing(VoEMediaProcess* object,
84 ProcessingTypes type);
85 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
87 int GetMixingFrequency();
90 int SetMute(bool enable);
94 int8_t AudioLevel() const;
96 int16_t AudioLevelFullRange() const;
98 bool IsRecordingCall();
100 bool IsRecordingMic();
102 int StartPlayingFileAsMicrophone(const char* fileName,
108 const CodecInst* codecInst);
110 int StartPlayingFileAsMicrophone(InStream* stream,
115 const CodecInst* codecInst);
117 int StopPlayingFileAsMicrophone();
119 int IsPlayingFileAsMicrophone() const;
121 int ScaleFileAsMicrophonePlayout(float scale);
123 int StartRecordingMicrophone(const char* fileName,
124 const CodecInst* codecInst);
126 int StartRecordingMicrophone(OutStream* stream,
127 const CodecInst* codecInst);
129 int StopRecordingMicrophone();
131 int StartRecordingCall(const char* fileName, const CodecInst* codecInst);
133 int StartRecordingCall(OutStream* stream, const CodecInst* codecInst);
135 int StopRecordingCall();
137 void SetMixWithMicStatus(bool mix);
139 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
141 virtual ~TransmitMixer();
144 void OnPeriodicProcess();
148 void PlayNotification(int32_t id,
149 uint32_t durationMs);
151 void RecordNotification(int32_t id,
152 uint32_t durationMs);
154 void PlayFileEnded(int32_t id);
156 void RecordFileEnded(int32_t id);
158 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
160 int TimeSinceLastTyping(int &seconds);
161 int SetTypingDetectionParameters(int timeWindow,
163 int reportingThreshold,
168 void EnableStereoChannelSwapping(bool enable);
169 bool IsStereoChannelSwappingEnabled();
172 TransmitMixer(uint32_t instanceId);
174 // Gets the maximum sample rate and number of channels over all currently
176 void GetSendCodecInfo(int* max_sample_rate, int* max_channels);
178 int GenerateAudioFrame(const int16_t audioSamples[],
182 int32_t RecordAudioToFile(uint32_t mixingFrequency);
184 int32_t MixOrReplaceAudioWithFile(
185 int mixingFrequency);
187 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level,
190 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
191 void TypingDetection(bool keyPressed);
195 Statistics* _engineStatisticsPtr;
196 ChannelManager* _channelManagerPtr;
197 AudioProcessing* audioproc_;
198 VoiceEngineObserver* _voiceEngineObserverPtr;
199 ProcessThread* _processThreadPtr;
202 MonitorModule _monitorModule;
203 AudioFrame _audioFrame;
204 PushResampler resampler_; // ADM sample rate -> mixing rate
205 FilePlayer* _filePlayerPtr;
206 FileRecorder* _fileRecorderPtr;
207 FileRecorder* _fileCallRecorderPtr;
210 int _fileCallRecorderId;
213 bool _fileCallRecording;
214 voe::AudioLevel _audioLevel;
215 // protect file instances and their variables in MixedParticipants()
216 CriticalSectionWrapper& _critSect;
217 CriticalSectionWrapper& _callbackCritSect;
219 #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
220 webrtc::TypingDetection _typingDetection;
221 bool _typingNoiseWarningPending;
222 bool _typingNoiseDetected;
224 bool _saturationWarning;
227 bool _mixFileWithMicrophone;
228 uint32_t _captureLevel;
229 VoEMediaProcess* external_postproc_ptr_;
230 VoEMediaProcess* external_preproc_ptr_;
232 int32_t _remainingMuteMicTimeMs;
234 bool swap_stereo_channels_;
239 } // namespace webrtc
241 #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H