transmit_mixer.h revision 40ee3d07eda24b8e8214429d9885d9ad9a2c04f7
1/* 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 "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/system_wrappers/interface/scoped_ptr.h" 21#include "webrtc/voice_engine/include/voe_base.h" 22#include "webrtc/voice_engine/level_indicator.h" 23#include "webrtc/voice_engine/monitor_module.h" 24#include "webrtc/voice_engine/voice_engine_defines.h" 25 26namespace webrtc { 27 28class AudioProcessing; 29class ProcessThread; 30class VoEExternalMedia; 31class VoEMediaProcess; 32 33namespace voe { 34 35class ChannelManager; 36class MixedAudio; 37class Statistics; 38 39class TransmitMixer : public MonitorObserver, 40 public FileCallback { 41public: 42 static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId); 43 44 static void Destroy(TransmitMixer*& mixer); 45 46 int32_t SetEngineInformation(ProcessThread& processThread, 47 Statistics& engineStatistics, 48 ChannelManager& channelManager); 49 50 int32_t SetAudioProcessingModule( 51 AudioProcessing* audioProcessingModule); 52 53 int32_t PrepareDemux(const void* audioSamples, 54 uint32_t nSamples, 55 uint8_t nChannels, 56 uint32_t samplesPerSec, 57 uint16_t totalDelayMS, 58 int32_t clockDrift, 59 uint16_t currentMicLevel, 60 bool keyPressed); 61 62 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); 67 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); 72 73 // Must be called on the same thread as PrepareDemux(). 74 uint32_t CaptureLevel() const; 75 76 int32_t StopSend(); 77 78 // VoEDtmf 79 void UpdateMuteMicrophoneTime(uint32_t lengthMs); 80 81 // VoEExternalMedia 82 int RegisterExternalMediaProcessing(VoEMediaProcess* object, 83 ProcessingTypes type); 84 int DeRegisterExternalMediaProcessing(ProcessingTypes type); 85 86 int GetMixingFrequency(); 87 88 // VoEVolumeControl 89 int SetMute(bool enable); 90 91 bool Mute() const; 92 93 int8_t AudioLevel() const; 94 95 int16_t AudioLevelFullRange() const; 96 97 bool IsRecordingCall(); 98 99 bool IsRecordingMic(); 100 101 int StartPlayingFileAsMicrophone(const char* fileName, 102 bool loop, 103 FileFormats format, 104 int startPosition, 105 float volumeScaling, 106 int stopPosition, 107 const CodecInst* codecInst); 108 109 int StartPlayingFileAsMicrophone(InStream* stream, 110 FileFormats format, 111 int startPosition, 112 float volumeScaling, 113 int stopPosition, 114 const CodecInst* codecInst); 115 116 int StopPlayingFileAsMicrophone(); 117 118 int IsPlayingFileAsMicrophone() const; 119 120 int ScaleFileAsMicrophonePlayout(float scale); 121 122 int StartRecordingMicrophone(const char* fileName, 123 const CodecInst* codecInst); 124 125 int StartRecordingMicrophone(OutStream* stream, 126 const CodecInst* codecInst); 127 128 int StopRecordingMicrophone(); 129 130 int StartRecordingCall(const char* fileName, const CodecInst* codecInst); 131 132 int StartRecordingCall(OutStream* stream, const CodecInst* codecInst); 133 134 int StopRecordingCall(); 135 136 void SetMixWithMicStatus(bool mix); 137 138 int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); 139 140 virtual ~TransmitMixer(); 141 142 // MonitorObserver 143 void OnPeriodicProcess(); 144 145 146 // FileCallback 147 void PlayNotification(int32_t id, 148 uint32_t durationMs); 149 150 void RecordNotification(int32_t id, 151 uint32_t durationMs); 152 153 void PlayFileEnded(int32_t id); 154 155 void RecordFileEnded(int32_t id); 156 157#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION 158 // Typing detection 159 int TimeSinceLastTyping(int &seconds); 160 int SetTypingDetectionParameters(int timeWindow, 161 int costPerTyping, 162 int reportingThreshold, 163 int penaltyDecay, 164 int typeEventDelay); 165#endif 166 167 void EnableStereoChannelSwapping(bool enable); 168 bool IsStereoChannelSwappingEnabled(); 169 170private: 171 TransmitMixer(uint32_t instanceId); 172 173 // Gets the maximum sample rate and number of channels over all currently 174 // sending codecs. 175 void GetSendCodecInfo(int* max_sample_rate, int* max_channels); 176 177 void GenerateAudioFrame(const int16_t audioSamples[], 178 int nSamples, 179 int nChannels, 180 int samplesPerSec); 181 int32_t RecordAudioToFile(uint32_t mixingFrequency); 182 183 int32_t MixOrReplaceAudioWithFile( 184 int mixingFrequency); 185 186 void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, 187 bool key_pressed); 188 189#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION 190 void TypingDetection(bool keyPressed); 191#endif 192 193 // uses 194 Statistics* _engineStatisticsPtr; 195 ChannelManager* _channelManagerPtr; 196 AudioProcessing* audioproc_; 197 VoiceEngineObserver* _voiceEngineObserverPtr; 198 ProcessThread* _processThreadPtr; 199 200 // owns 201 MonitorModule _monitorModule; 202 AudioFrame _audioFrame; 203 PushResampler resampler_; // ADM sample rate -> mixing rate 204 FilePlayer* _filePlayerPtr; 205 FileRecorder* _fileRecorderPtr; 206 FileRecorder* _fileCallRecorderPtr; 207 int _filePlayerId; 208 int _fileRecorderId; 209 int _fileCallRecorderId; 210 bool _filePlaying; 211 bool _fileRecording; 212 bool _fileCallRecording; 213 voe::AudioLevel _audioLevel; 214 // protect file instances and their variables in MixedParticipants() 215 CriticalSectionWrapper& _critSect; 216 CriticalSectionWrapper& _callbackCritSect; 217 218#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION 219 webrtc::TypingDetection _typingDetection; 220 bool _typingNoiseWarningPending; 221 bool _typingNoiseDetected; 222#endif 223 bool _saturationWarning; 224 225 int _instanceId; 226 bool _mixFileWithMicrophone; 227 uint32_t _captureLevel; 228 VoEMediaProcess* external_postproc_ptr_; 229 VoEMediaProcess* external_preproc_ptr_; 230 bool _mute; 231 int32_t _remainingMuteMicTimeMs; 232 bool stereo_codec_; 233 bool swap_stereo_channels_; 234 scoped_ptr<int16_t[]> mono_buffer_; 235}; 236 237} // namespace voe 238 239} // namespace webrtc 240 241#endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H 242