blob: f01362f5da802f541dd5d29949ca3293b398647d [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:
pbos@webrtc.org6141e132013-04-09 10:09:10 +000043 static int32_t Create(TransmitMixer*& mixer, const uint32_t instanceId);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45 static void Destroy(TransmitMixer*& mixer);
46
pbos@webrtc.org6141e132013-04-09 10:09:10 +000047 int32_t SetEngineInformation(ProcessThread& processThread,
48 Statistics& engineStatistics,
49 ChannelManager& channelManager);
niklase@google.com470e71d2011-07-07 08:21:25 +000050
pbos@webrtc.org6141e132013-04-09 10:09:10 +000051 int32_t SetAudioProcessingModule(
niklase@google.com470e71d2011-07-07 08:21:25 +000052 AudioProcessing* audioProcessingModule);
53
pbos@webrtc.org6141e132013-04-09 10:09:10 +000054 int32_t PrepareDemux(const void* audioSamples,
55 const uint32_t nSamples,
56 const uint8_t nChannels,
57 const uint32_t samplesPerSec,
58 const uint16_t totalDelayMS,
59 const int32_t clockDrift,
60 const uint16_t currentMicLevel);
niklase@google.com470e71d2011-07-07 08:21:25 +000061
62
pbos@webrtc.org6141e132013-04-09 10:09:10 +000063 int32_t DemuxAndMix();
niklase@google.com470e71d2011-07-07 08:21:25 +000064
pbos@webrtc.org6141e132013-04-09 10:09:10 +000065 int32_t EncodeAndSend();
niklase@google.com470e71d2011-07-07 08:21:25 +000066
pbos@webrtc.org6141e132013-04-09 10:09:10 +000067 uint32_t CaptureLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000068
pbos@webrtc.org6141e132013-04-09 10:09:10 +000069 int32_t StopSend();
niklase@google.com470e71d2011-07-07 08:21:25 +000070
niklase@google.com470e71d2011-07-07 08:21:25 +000071 // VoEDtmf
pbos@webrtc.org6141e132013-04-09 10:09:10 +000072 void UpdateMuteMicrophoneTime(const uint32_t lengthMs);
niklase@google.com470e71d2011-07-07 08:21:25 +000073
74 // VoEExternalMedia
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +000075 int RegisterExternalMediaProcessing(VoEMediaProcess* object,
76 ProcessingTypes type);
77 int DeRegisterExternalMediaProcessing(ProcessingTypes type);
niklase@google.com470e71d2011-07-07 08:21:25 +000078
xians@google.com0b0665a2011-08-08 08:18:44 +000079 int GetMixingFrequency();
niklase@google.com470e71d2011-07-07 08:21:25 +000080
81 // VoEVolumeControl
82 int SetMute(const bool enable);
83
84 bool Mute() const;
85
pbos@webrtc.org6141e132013-04-09 10:09:10 +000086 int8_t AudioLevel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
pbos@webrtc.org6141e132013-04-09 10:09:10 +000088 int16_t AudioLevelFullRange() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000089
90 bool IsRecordingCall();
91
92 bool IsRecordingMic();
93
94 int StartPlayingFileAsMicrophone(const char* fileName,
95 const bool loop,
96 const FileFormats format,
97 const int startPosition,
98 const float volumeScaling,
99 const int stopPosition,
100 const CodecInst* codecInst);
101
102 int StartPlayingFileAsMicrophone(InStream* stream,
103 const FileFormats format,
104 const int startPosition,
105 const float volumeScaling,
106 const int stopPosition,
107 const CodecInst* codecInst);
108
109 int StopPlayingFileAsMicrophone();
110
111 int IsPlayingFileAsMicrophone() const;
112
113 int ScaleFileAsMicrophonePlayout(const float scale);
114
115 int StartRecordingMicrophone(const char* fileName,
116 const CodecInst* codecInst);
117
118 int StartRecordingMicrophone(OutStream* stream,
119 const CodecInst* codecInst);
120
121 int StopRecordingMicrophone();
122
123 int StartRecordingCall(const char* fileName, const CodecInst* codecInst);
124
125 int StartRecordingCall(OutStream* stream, const CodecInst* codecInst);
126
127 int StopRecordingCall();
128
129 void SetMixWithMicStatus(bool mix);
130
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000131 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
133 virtual ~TransmitMixer();
134
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000135 // MonitorObserver
niklase@google.com470e71d2011-07-07 08:21:25 +0000136 void OnPeriodicProcess();
137
138
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000139 // FileCallback
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000140 void PlayNotification(const int32_t id,
141 const uint32_t durationMs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000143 void RecordNotification(const int32_t id,
144 const uint32_t durationMs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000146 void PlayFileEnded(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000148 void RecordFileEnded(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000150#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000151 // Typing detection
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000152 int TimeSinceLastTyping(int &seconds);
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000153 int SetTypingDetectionParameters(int timeWindow,
154 int costPerTyping,
155 int reportingThreshold,
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +0000156 int penaltyDecay,
157 int typeEventDelay);
niklas.enbom@webrtc.org3dc88652012-03-30 09:53:54 +0000158#endif
159
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000160 void EnableStereoChannelSwapping(bool enable);
161 bool IsStereoChannelSwappingEnabled();
162
niklase@google.com470e71d2011-07-07 08:21:25 +0000163private:
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000164 TransmitMixer(const uint32_t instanceId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
andrew@webrtc.org24120852013-03-02 00:14:46 +0000166 // Gets the maximum sample rate and number of channels over all currently
167 // sending codecs.
168 void GetSendCodecInfo(int* max_sample_rate, int* max_channels);
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +0000169
170 int GenerateAudioFrame(const int16_t audioSamples[],
171 int nSamples,
172 int nChannels,
173 int samplesPerSec);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000174 int32_t RecordAudioToFile(const uint32_t mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000176 int32_t MixOrReplaceAudioWithFile(
xians@google.com0b0665a2011-08-08 08:18:44 +0000177 const int mixingFrequency);
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000179 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
181#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
182 int TypingDetection();
183#endif
184
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000185 // uses
niklase@google.com470e71d2011-07-07 08:21:25 +0000186 Statistics* _engineStatisticsPtr;
187 ChannelManager* _channelManagerPtr;
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000188 AudioProcessing* audioproc_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000189 VoiceEngineObserver* _voiceEngineObserverPtr;
190 ProcessThread* _processThreadPtr;
191
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000192 // owns
niklase@google.com470e71d2011-07-07 08:21:25 +0000193 MonitorModule _monitorModule;
194 AudioFrame _audioFrame;
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +0000195 Resampler _audioResampler; // ADM sample rate -> mixing rate
196 FilePlayer* _filePlayerPtr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000197 FileRecorder* _fileRecorderPtr;
198 FileRecorder* _fileCallRecorderPtr;
xians@google.com0b0665a2011-08-08 08:18:44 +0000199 int _filePlayerId;
200 int _fileRecorderId;
201 int _fileCallRecorderId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000202 bool _filePlaying;
203 bool _fileRecording;
204 bool _fileCallRecording;
205 voe::AudioLevel _audioLevel;
206 // protect file instances and their variables in MixedParticipants()
207 CriticalSectionWrapper& _critSect;
208 CriticalSectionWrapper& _callbackCritSect;
209
210#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000211 int32_t _timeActive;
212 int32_t _timeSinceLastTyping;
213 int32_t _penaltyCounter;
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000214 bool _typingNoiseWarning;
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000215
216 // Tunable treshold values
217 int _timeWindow; // nr of10ms slots accepted to count as a hit.
218 int _costPerTyping; // Penalty added for a typing + activity coincide.
219 int _reportingThreshold; // Threshold for _penaltyCounter.
220 int _penaltyDecay; // How much we reduce _penaltyCounter every 10 ms.
niklas.enbom@webrtc.orgf6edfef2012-05-09 13:16:12 +0000221 int _typeEventDelay; // How old typing events we allow
niklas.enbom@webrtc.org06e722a2012-04-04 07:44:27 +0000222
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#endif
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000224 bool _saturationWarning;
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
xians@google.com0b0665a2011-08-08 08:18:44 +0000226 int _instanceId;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227 bool _mixFileWithMicrophone;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000228 uint32_t _captureLevel;
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +0000229 VoEMediaProcess* external_postproc_ptr_;
230 VoEMediaProcess* external_preproc_ptr_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 bool _mute;
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000232 int32_t _remainingMuteMicTimeMs;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +0000233 bool stereo_codec_;
andrew@webrtc.org02d71742012-04-24 19:47:00 +0000234 bool swap_stereo_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000235};
236
237#endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
238
239} // namespace voe
240
241} // namespace webrtc