Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / voice_engine / voe_base_impl.h
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_VOE_BASE_IMPL_H
12 #define WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H
13
14 #include "webrtc/voice_engine/include/voe_base.h"
15
16 #include "webrtc/modules/interface/module_common_types.h"
17 #include "webrtc/voice_engine/shared_data.h"
18
19 namespace webrtc
20 {
21
22 class ProcessThread;
23
24 class VoEBaseImpl: public VoEBase,
25                    public AudioTransport,
26                    public AudioDeviceObserver
27 {
28 public:
29     virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
30
31     virtual int DeRegisterVoiceEngineObserver();
32
33     virtual int Init(AudioDeviceModule* external_adm = NULL,
34                      AudioProcessing* audioproc = NULL);
35     virtual AudioProcessing* audio_processing() {
36       return _shared->audio_processing();
37     }
38
39     virtual int Terminate();
40
41     virtual int CreateChannel();
42     virtual int CreateChannel(const Config& config);
43
44     virtual int DeleteChannel(int channel);
45
46     virtual int StartReceive(int channel);
47
48     virtual int StartPlayout(int channel);
49
50     virtual int StartSend(int channel);
51
52     virtual int StopReceive(int channel);
53
54     virtual int StopPlayout(int channel);
55
56     virtual int StopSend(int channel);
57
58     virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode);
59
60     virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode);
61
62     virtual int SetOnHoldStatus(int channel,
63                                 bool enable,
64                                 OnHoldModes mode = kHoldSendAndPlay);
65
66     virtual int GetOnHoldStatus(int channel, bool& enabled, OnHoldModes& mode);
67
68     virtual int GetVersion(char version[1024]);
69
70     virtual int LastError();
71
72     virtual AudioTransport* audio_transport() { return this; }
73
74     // AudioTransport
75     virtual int32_t
76         RecordedDataIsAvailable(const void* audioSamples,
77                                 uint32_t nSamples,
78                                 uint8_t nBytesPerSample,
79                                 uint8_t nChannels,
80                                 uint32_t samplesPerSec,
81                                 uint32_t totalDelayMS,
82                                 int32_t clockDrift,
83                                 uint32_t currentMicLevel,
84                                 bool keyPressed,
85                                 uint32_t& newMicLevel);
86
87     virtual int32_t NeedMorePlayData(uint32_t nSamples,
88                                      uint8_t nBytesPerSample,
89                                      uint8_t nChannels,
90                                      uint32_t samplesPerSec,
91                                      void* audioSamples,
92                                      uint32_t& nSamplesOut);
93
94     virtual int OnDataAvailable(const int voe_channels[],
95                                 int number_of_voe_channels,
96                                 const int16_t* audio_data,
97                                 int sample_rate,
98                                 int number_of_channels,
99                                 int number_of_frames,
100                                 int audio_delay_milliseconds,
101                                 int current_volume,
102                                 bool key_pressed,
103                                 bool need_audio_processing);
104
105     virtual void OnData(int voe_channel, const void* audio_data,
106                         int bits_per_sample, int sample_rate,
107                         int number_of_channels, int number_of_frames);
108
109     // AudioDeviceObserver
110     virtual void OnErrorIsReported(ErrorCode error);
111     virtual void OnWarningIsReported(WarningCode warning);
112
113 protected:
114     VoEBaseImpl(voe::SharedData* shared);
115     virtual ~VoEBaseImpl();
116
117 private:
118     int32_t StartPlayout();
119     int32_t StopPlayout();
120     int32_t StartSend();
121     int32_t StopSend();
122     int32_t TerminateInternal();
123
124     // Helper function to process the recorded data with AudioProcessing Module,
125     // demultiplex the data to specific voe channels, encode and send to the
126     // network. When |number_of_VoE_channels| is 0, it will demultiplex the
127     // data to all the existing VoE channels.
128     // It returns new AGC microphone volume or 0 if no volume changes
129     // should be done.
130     int ProcessRecordedDataWithAPM(const int voe_channels[],
131                                    int number_of_voe_channels,
132                                    const void* audio_data,
133                                    uint32_t sample_rate,
134                                    uint8_t number_of_channels,
135                                    uint32_t number_of_frames,
136                                    uint32_t audio_delay_milliseconds,
137                                    int32_t clock_drift,
138                                    uint32_t current_volume,
139                                    bool key_pressed);
140
141     int32_t AddBuildInfo(char* str) const;
142     int32_t AddVoEVersion(char* str) const;
143
144     // Initialize channel by setting Engine Information then initializing
145     // channel.
146     int InitializeChannel(voe::ChannelOwner* channel_owner);
147 #ifdef WEBRTC_EXTERNAL_TRANSPORT
148     int32_t AddExternalTransportBuild(char* str) const;
149 #endif
150 #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
151     int32_t AddExternalRecAndPlayoutBuild(char* str) const;
152 #endif
153     VoiceEngineObserver* _voiceEngineObserverPtr;
154     CriticalSectionWrapper& _callbackCritSect;
155
156     bool _voiceEngineObserver;
157     uint32_t _oldVoEMicLevel;
158     uint32_t _oldMicLevel;
159     AudioFrame _audioFrame;
160     voe::SharedData* _shared;
161 };
162
163 }  // namespace webrtc
164
165 #endif  // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H