/* * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H #define WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H #include "common_types.h" #include "voe_base.h" #include "file_player.h" #include "file_recorder.h" #include "level_indicator.h" #include "module_common_types.h" #include "monitor_module.h" #include "resampler.h" #include "voice_engine_defines.h" namespace webrtc { class AudioProcessing; class ProcessThread; class VoEExternalMedia; class VoEMediaProcess; namespace voe { class ChannelManager; class MixedAudio; class Statistics; class TransmitMixer : public MonitorObserver, public FileCallback { public: static WebRtc_Word32 Create(TransmitMixer*& mixer, const WebRtc_UWord32 instanceId); static void Destroy(TransmitMixer*& mixer); WebRtc_Word32 SetEngineInformation(ProcessThread& processThread, Statistics& engineStatistics, ChannelManager& channelManager); WebRtc_Word32 SetAudioProcessingModule( AudioProcessing* audioProcessingModule); WebRtc_Word32 PrepareDemux(const WebRtc_Word8* audioSamples, const WebRtc_UWord32 nSamples, const WebRtc_UWord8 nChannels, const WebRtc_UWord32 samplesPerSec, const WebRtc_UWord16 totalDelayMS, const WebRtc_Word32 clockDrift, const WebRtc_UWord16 currentMicLevel); WebRtc_Word32 DemuxAndMix(); WebRtc_Word32 EncodeAndSend(); WebRtc_UWord32 CaptureLevel() const; WebRtc_Word32 StopSend(); void SetRTPAudioLevelIndicationStatus(bool enable) { _includeAudioLevelIndication = enable; } // VoEDtmf void UpdateMuteMicrophoneTime(const WebRtc_UWord32 lengthMs); // VoEExternalMedia int RegisterExternalMediaProcessing(VoEMediaProcess& proccess_object); int DeRegisterExternalMediaProcessing(); WebRtc_UWord32 GetMixingFrequency(); // VoEVolumeControl int SetMute(const bool enable); bool Mute() const; WebRtc_Word8 AudioLevel() const; WebRtc_Word16 AudioLevelFullRange() const; bool IsRecordingCall(); bool IsRecordingMic(); int StartPlayingFileAsMicrophone(const char* fileName, const bool loop, const FileFormats format, const int startPosition, const float volumeScaling, const int stopPosition, const CodecInst* codecInst); int StartPlayingFileAsMicrophone(InStream* stream, const FileFormats format, const int startPosition, const float volumeScaling, const int stopPosition, const CodecInst* codecInst); int StopPlayingFileAsMicrophone(); int IsPlayingFileAsMicrophone() const; int ScaleFileAsMicrophonePlayout(const float scale); int StartRecordingMicrophone(const char* fileName, const CodecInst* codecInst); int StartRecordingMicrophone(OutStream* stream, const CodecInst* codecInst); int StopRecordingMicrophone(); int StartRecordingCall(const char* fileName, const CodecInst* codecInst); int StartRecordingCall(OutStream* stream, const CodecInst* codecInst); int StopRecordingCall(); void SetMixWithMicStatus(bool mix); WebRtc_Word32 RegisterVoiceEngineObserver(VoiceEngineObserver& observer); virtual ~TransmitMixer(); public: // MonitorObserver void OnPeriodicProcess(); public: // FileCallback void PlayNotification(const WebRtc_Word32 id, const WebRtc_UWord32 durationMs); void RecordNotification(const WebRtc_Word32 id, const WebRtc_UWord32 durationMs); void PlayFileEnded(const WebRtc_Word32 id); void RecordFileEnded(const WebRtc_Word32 id); private: TransmitMixer(const WebRtc_UWord32 instanceId); private: WebRtc_Word32 GenerateAudioFrame(const WebRtc_Word16 audioSamples[], const WebRtc_UWord32 nSamples, const WebRtc_UWord8 nChannels, const WebRtc_UWord32 samplesPerSec, const WebRtc_UWord32 mixingFrequency); WebRtc_Word32 RecordAudioToFile(const WebRtc_UWord32 mixingFrequency); WebRtc_Word32 MixOrReplaceAudioWithFile( const WebRtc_UWord32 mixingFrequency); WebRtc_Word32 APMProcessStream(const WebRtc_UWord16 totalDelayMS, const WebRtc_Word32 clockDrift, const WebRtc_UWord16 currentMicLevel); #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION int TypingDetection(); #endif private: // uses Statistics* _engineStatisticsPtr; ChannelManager* _channelManagerPtr; AudioProcessing* _audioProcessingModulePtr; VoiceEngineObserver* _voiceEngineObserverPtr; ProcessThread* _processThreadPtr; private: // owns MonitorModule _monitorModule; AudioFrame _audioFrame; Resampler _audioResampler; // ADM sample rate -> mixing rate FilePlayer* _filePlayerPtr; FileRecorder* _fileRecorderPtr; FileRecorder* _fileCallRecorderPtr; WebRtc_UWord32 _filePlayerId; WebRtc_UWord32 _fileRecorderId; WebRtc_UWord32 _fileCallRecorderId; bool _filePlaying; bool _fileRecording; bool _fileCallRecording; voe::AudioLevel _audioLevel; // protect file instances and their variables in MixedParticipants() CriticalSectionWrapper& _critSect; CriticalSectionWrapper& _callbackCritSect; #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION WebRtc_Word32 _timeActive; WebRtc_Word32 _penaltyCounter; WebRtc_UWord32 _typingNoiseWarning; #endif WebRtc_UWord32 _saturationWarning; WebRtc_UWord32 _noiseWarning; private: WebRtc_UWord32 _instanceId; bool _mixFileWithMicrophone; WebRtc_UWord32 _captureLevel; bool _externalMedia; VoEMediaProcess* _externalMediaCallbackPtr; bool _mute; WebRtc_Word32 _remainingMuteMicTimeMs; WebRtc_UWord32 _mixingFrequency; bool _includeAudioLevelIndication; WebRtc_UWord8 _audioLevel_dBov; }; #endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H } // namespace voe } // namespace webrtc