blob: 7863cd48ec9fc02c290407f94ce465f09caea039 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
henrika@webrtc.org907bc552012-03-09 08:59:19 +000055 WebRtc_Word32 PrepareDemux(const void* audioSamples,
niklase@google.com470e71d2011-07-07 08:21:25 +000056 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
niklase@google.com470e71d2011-07-07 08:21:25 +000072 // VoEDtmf
73 void UpdateMuteMicrophoneTime(const WebRtc_UWord32 lengthMs);
74
75 // VoEExternalMedia
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +000076 int RegisterExternalMediaProcessing(VoEMediaProcess* object,
77 ProcessingTypes type);
78 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
xians@google.com0b0665a2011-08-08 08:18:44 +000080 int GetMixingFrequency();
niklase@google.com470e71d2011-07-07 08:21:25 +000081
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
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000136 // MonitorObserver
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 void OnPeriodicProcess();
138
139
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000140 // FileCallback
niklase@google.com470e71d2011-07-07 08:21:25 +0000141 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
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000151#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000152 // Typing detection
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000153 int TimeSinceLastTyping(int &seconds);
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000154 int SetTypingDetectionParameters(int timeWindow,
155 int costPerTyping,
156 int reportingThreshold,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +0000157 int penaltyDecay,
158 int typeEventDelay);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000159#endif
160
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000161 void EnableStereoChannelSwapping(bool enable);
162 bool IsStereoChannelSwappingEnabled();
163
niklase@google.com470e71d2011-07-07 08:21:25 +0000164private:
165 TransmitMixer(const WebRtc_UWord32 instanceId);
166
andrew@webrtc.org24120852013-03-02 00:14:46 +0000167 // Gets the maximum sample rate and number of channels over all currently
168 // sending codecs.
169 void GetSendCodecInfo(int* max_sample_rate, int* max_channels);
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +0000170
171 int GenerateAudioFrame(const int16_t audioSamples[],
172 int nSamples,
173 int nChannels,
174 int samplesPerSec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 WebRtc_Word32 RecordAudioToFile(const WebRtc_UWord32 mixingFrequency);
176
177 WebRtc_Word32 MixOrReplaceAudioWithFile(
xians@google.com0b0665a2011-08-08 08:18:44 +0000178 const int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000180 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
182#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
183 int TypingDetection();
184#endif
185
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000186 // uses
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 Statistics* _engineStatisticsPtr;
188 ChannelManager* _channelManagerPtr;
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000189 AudioProcessing* audioproc_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000190 VoiceEngineObserver* _voiceEngineObserverPtr;
191 ProcessThread* _processThreadPtr;
192
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000193 // owns
niklase@google.com470e71d2011-07-07 08:21:25 +0000194 MonitorModule _monitorModule;
195 AudioFrame _audioFrame;
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +0000196 Resampler _audioResampler; // ADM sample rate -> mixing rate
197 FilePlayer* _filePlayerPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 FileRecorder* _fileRecorderPtr;
199 FileRecorder* _fileCallRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000200 int _filePlayerId;
201 int _fileRecorderId;
202 int _fileCallRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000203 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;
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000213 WebRtc_Word32 _timeSinceLastTyping;
niklase@google.com470e71d2011-07-07 08:21:25 +0000214 WebRtc_Word32 _penaltyCounter;
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000215 bool _typingNoiseWarning;
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000216
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.
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +0000222 int _typeEventDelay; // How old typing events we allow
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000223
niklase@google.com470e71d2011-07-07 08:21:25 +0000224#endif
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000225 bool _saturationWarning;
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
xians@google.com0b0665a2011-08-08 08:18:44 +0000227 int _instanceId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 bool _mixFileWithMicrophone;
229 WebRtc_UWord32 _captureLevel;
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +0000230 VoEMediaProcess* external_postproc_ptr_;
231 VoEMediaProcess* external_preproc_ptr_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000232 bool _mute;
233 WebRtc_Word32 _remainingMuteMicTimeMs;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +0000234 bool stereo_codec_;
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000235 bool swap_stereo_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236};
237
238#endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
239
240} // namespace voe
241
242} // namespace webrtc