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