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_OUTPUT_MIXER_H_ 12 #define WEBRTC_VOICE_ENGINE_OUTPUT_MIXER_H_ 13 14 #include "webrtc/common_audio/resampler/include/push_resampler.h" 15 #include "webrtc/common_types.h" 16 #include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer.h" 17 #include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h" 18 #include "webrtc/modules/utility/interface/file_recorder.h" 19 #include "webrtc/voice_engine/dtmf_inband.h" 20 #include "webrtc/voice_engine/level_indicator.h" 21 #include "webrtc/voice_engine/voice_engine_defines.h" 22 23 namespace webrtc { 24 25 class AudioProcessing; 26 class CriticalSectionWrapper; 27 class FileWrapper; 28 class VoEMediaProcess; 29 30 namespace voe { 31 32 class Statistics; 33 34 class OutputMixer : public AudioMixerOutputReceiver, 35 public AudioMixerStatusReceiver, 36 public FileCallback 37 { 38 public: 39 static int32_t Create(OutputMixer*& mixer, uint32_t instanceId); 40 41 static void Destroy(OutputMixer*& mixer); 42 43 int32_t SetEngineInformation(Statistics& engineStatistics); 44 45 int32_t SetAudioProcessingModule( 46 AudioProcessing* audioProcessingModule); 47 48 // VoEExternalMedia 49 int RegisterExternalMediaProcessing( 50 VoEMediaProcess& proccess_object); 51 52 int DeRegisterExternalMediaProcessing(); 53 54 // VoEDtmf 55 int PlayDtmfTone(uint8_t eventCode, int lengthMs, int attenuationDb); 56 57 int32_t MixActiveChannels(); 58 59 int32_t DoOperationsOnCombinedSignal(bool feed_data_to_apm); 60 61 int32_t SetMixabilityStatus(MixerParticipant& participant, 62 bool mixable); 63 64 int32_t SetAnonymousMixabilityStatus(MixerParticipant& participant, 65 bool mixable); 66 67 int GetMixedAudio(int sample_rate_hz, int num_channels, 68 AudioFrame* audioFrame); 69 70 // VoEVolumeControl 71 int GetSpeechOutputLevel(uint32_t& level); 72 73 int GetSpeechOutputLevelFullRange(uint32_t& level); 74 75 int SetOutputVolumePan(float left, float right); 76 77 int GetOutputVolumePan(float& left, float& right); 78 79 // VoEFile 80 int StartRecordingPlayout(const char* fileName, 81 const CodecInst* codecInst); 82 83 int StartRecordingPlayout(OutStream* stream, 84 const CodecInst* codecInst); 85 int StopRecordingPlayout(); 86 87 virtual ~OutputMixer(); 88 89 // from AudioMixerOutputReceiver 90 virtual void NewMixedAudio( 91 int32_t id, 92 const AudioFrame& generalAudioFrame, 93 const AudioFrame** uniqueAudioFrames, 94 uint32_t size); 95 96 // from AudioMixerStatusReceiver 97 virtual void MixedParticipants( 98 int32_t id, 99 const ParticipantStatistics* participantStatistics, 100 uint32_t size); 101 102 virtual void VADPositiveParticipants( 103 int32_t id, 104 const ParticipantStatistics* participantStatistics, 105 uint32_t size); 106 107 virtual void MixedAudioLevel(int32_t id, uint32_t level); 108 109 // For file recording 110 void PlayNotification(int32_t id, uint32_t durationMs); 111 112 void RecordNotification(int32_t id, uint32_t durationMs); 113 114 void PlayFileEnded(int32_t id); 115 void RecordFileEnded(int32_t id); 116 117 private: 118 OutputMixer(uint32_t instanceId); 119 void APMAnalyzeReverseStream(); 120 int InsertInbandDtmfTone(); 121 122 // uses 123 Statistics* _engineStatisticsPtr; 124 AudioProcessing* _audioProcessingModulePtr; 125 126 // owns 127 CriticalSectionWrapper& _callbackCritSect; 128 // protect the _outputFileRecorderPtr and _outputFileRecording 129 CriticalSectionWrapper& _fileCritSect; 130 AudioConferenceMixer& _mixerModule; 131 AudioFrame _audioFrame; 132 // Converts mixed audio to the audio device output rate. 133 PushResampler<int16_t> resampler_; 134 // Converts mixed audio to the audio processing rate. 135 PushResampler<int16_t> audioproc_resampler_; 136 AudioLevel _audioLevel; // measures audio level for the combined signal 137 DtmfInband _dtmfGenerator; 138 int _instanceId; 139 VoEMediaProcess* _externalMediaCallbackPtr; 140 bool _externalMedia; 141 float _panLeft; 142 float _panRight; 143 int _mixingFrequencyHz; 144 FileRecorder* _outputFileRecorderPtr; 145 bool _outputFileRecording; 146 }; 147 148 } // namespace voe 149 150 } // namespace werbtc 151 152 #endif // VOICE_ENGINE_OUTPUT_MIXER_H_ 153