blob: 0dac0499347d8011b9a63792b309b35454c97f57 [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
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
14#include "common_types.h"
15#include "voe_base.h"
16#include "file_player.h"
17#include "file_recorder.h"
18#include "level_indicator.h"
19#include "module_common_types.h"
20#include "monitor_module.h"
21#include "resampler.h"
22#include "voice_engine_defines.h"
23
24
25namespace webrtc {
26
27class AudioProcessing;
28class ProcessThread;
29class VoEExternalMedia;
30class VoEMediaProcess;
31
32namespace voe {
33
34class ChannelManager;
35class MixedAudio;
36class Statistics;
37
38class TransmitMixer : public MonitorObserver,
39 public FileCallback
40
41{
42public:
43 static WebRtc_Word32 Create(TransmitMixer*& mixer,
44 const WebRtc_UWord32 instanceId);
45
46 static void Destroy(TransmitMixer*& mixer);
47
48 WebRtc_Word32 SetEngineInformation(ProcessThread& processThread,
49 Statistics& engineStatistics,
50 ChannelManager& channelManager);
51
52 WebRtc_Word32 SetAudioProcessingModule(
53 AudioProcessing* audioProcessingModule);
54
55 WebRtc_Word32 PrepareDemux(const void* audioSamples,
56 const WebRtc_UWord32 nSamples,
57 const WebRtc_UWord8 nChannels,
58 const WebRtc_UWord32 samplesPerSec,
59 const WebRtc_UWord16 totalDelayMS,
60 const WebRtc_Word32 clockDrift,
61 const WebRtc_UWord16 currentMicLevel);
62
63
64 WebRtc_Word32 DemuxAndMix();
65
66 WebRtc_Word32 EncodeAndSend();
67
68 WebRtc_UWord32 CaptureLevel() const;
69
70 WebRtc_Word32 StopSend();
71
72 // VoEDtmf
73 void UpdateMuteMicrophoneTime(const WebRtc_UWord32 lengthMs);
74
75 // VoEExternalMedia
76 int RegisterExternalMediaProcessing(VoEMediaProcess* object,
77 ProcessingTypes type);
78 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
79
80 int GetMixingFrequency();
81
82 // VoEVolumeControl
83 int SetMute(const bool enable);
84
85 bool Mute() const;
86
87 WebRtc_Word8 AudioLevel() const;
88
89 WebRtc_Word16 AudioLevelFullRange() const;
90
91 bool IsRecordingCall();
92
93 bool IsRecordingMic();
94
95 int StartPlayingFileAsMicrophone(const char* fileName,
96 const bool loop,
97 const FileFormats format,
98 const int startPosition,
99 const float volumeScaling,
100 const int stopPosition,
101 const CodecInst* codecInst);
102
103 int StartPlayingFileAsMicrophone(InStream* stream,
104 const FileFormats format,
105 const int startPosition,
106 const float volumeScaling,
107 const int stopPosition,
108 const CodecInst* codecInst);
109
110 int StopPlayingFileAsMicrophone();
111
112 int IsPlayingFileAsMicrophone() const;
113
114 int ScaleFileAsMicrophonePlayout(const float scale);
115
116 int StartRecordingMicrophone(const char* fileName,
117 const CodecInst* codecInst);
118
119 int StartRecordingMicrophone(OutStream* stream,
120 const CodecInst* codecInst);
121
122 int StopRecordingMicrophone();
123
124 int StartRecordingCall(const char* fileName, const CodecInst* codecInst);
125
126 int StartRecordingCall(OutStream* stream, const CodecInst* codecInst);
127
128 int StopRecordingCall();
129
130 void SetMixWithMicStatus(bool mix);
131
132 WebRtc_Word32 RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
133
134 virtual ~TransmitMixer();
135
136 // MonitorObserver
137 void OnPeriodicProcess();
138
139
140 // FileCallback
141 void PlayNotification(const WebRtc_Word32 id,
142 const WebRtc_UWord32 durationMs);
143
144 void RecordNotification(const WebRtc_Word32 id,
145 const WebRtc_UWord32 durationMs);
146
147 void PlayFileEnded(const WebRtc_Word32 id);
148
149 void RecordFileEnded(const WebRtc_Word32 id);
150
151#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
152 // Typing detection
153 int TimeSinceLastTyping(int &seconds);
154 int SetTypingDetectionParameters(int timeWindow,
155 int costPerTyping,
156 int reportingThreshold,
157 int penaltyDecay,
158 int typeEventDelay);
159#endif
160
161 void EnableStereoChannelSwapping(bool enable);
162 bool IsStereoChannelSwappingEnabled();
163
164private:
165 TransmitMixer(const WebRtc_UWord32 instanceId);
166
167 void CheckForSendCodecChanges();
168
169 int GenerateAudioFrame(const int16_t audioSamples[],
170 int nSamples,
171 int nChannels,
172 int samplesPerSec);
173 WebRtc_Word32 RecordAudioToFile(const WebRtc_UWord32 mixingFrequency);
174
175 WebRtc_Word32 MixOrReplaceAudioWithFile(
176 const int mixingFrequency);
177
178 WebRtc_Word32 APMProcessStream(const WebRtc_UWord16 totalDelayMS,
179 const WebRtc_Word32 clockDrift,
180 const WebRtc_UWord16 currentMicLevel);
181
182#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
183 int TypingDetection();
184#endif
185
186 // uses
187 Statistics* _engineStatisticsPtr;
188 ChannelManager* _channelManagerPtr;
189 AudioProcessing* _audioProcessingModulePtr;
190 VoiceEngineObserver* _voiceEngineObserverPtr;
191 ProcessThread* _processThreadPtr;
192
193 // owns
194 MonitorModule _monitorModule;
195 AudioFrame _audioFrame;
196 Resampler _audioResampler; // ADM sample rate -> mixing rate
197 FilePlayer* _filePlayerPtr;
198 FileRecorder* _fileRecorderPtr;
199 FileRecorder* _fileCallRecorderPtr;
200 int _filePlayerId;
201 int _fileRecorderId;
202 int _fileCallRecorderId;
203 bool _filePlaying;
204 bool _fileRecording;
205 bool _fileCallRecording;
206 voe::AudioLevel _audioLevel;
207 // protect file instances and their variables in MixedParticipants()
208 CriticalSectionWrapper& _critSect;
209 CriticalSectionWrapper& _callbackCritSect;
210
211#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
212 WebRtc_Word32 _timeActive;
213 WebRtc_Word32 _timeSinceLastTyping;
214 WebRtc_Word32 _penaltyCounter;
215 WebRtc_UWord32 _typingNoiseWarning;
216
217 // Tunable treshold values
218 int _timeWindow; // nr of10ms slots accepted to count as a hit.
219 int _costPerTyping; // Penalty added for a typing + activity coincide.
220 int _reportingThreshold; // Threshold for _penaltyCounter.
221 int _penaltyDecay; // How much we reduce _penaltyCounter every 10 ms.
222 int _typeEventDelay; // How old typing events we allow
223
224#endif
225 WebRtc_UWord32 _saturationWarning;
226 WebRtc_UWord32 _noiseWarning;
227
228 int _instanceId;
229 bool _mixFileWithMicrophone;
230 WebRtc_UWord32 _captureLevel;
231 VoEMediaProcess* external_postproc_ptr_;
232 VoEMediaProcess* external_preproc_ptr_;
233 bool _mute;
234 WebRtc_Word32 _remainingMuteMicTimeMs;
235 int _mixingFrequency;
236 bool stereo_codec_;
237 bool swap_stereo_channels_;
238};
239
240#endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
241
242} // namespace voe
243
244} // namespace webrtc