Upstream version 7.36.149.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 GetVersion(char version[1024]);
59
60     virtual int LastError();
61
62     virtual AudioTransport* audio_transport() { return this; }
63
64     // AudioTransport
65     virtual int32_t
66         RecordedDataIsAvailable(const void* audioSamples,
67                                 uint32_t nSamples,
68                                 uint8_t nBytesPerSample,
69                                 uint8_t nChannels,
70                                 uint32_t samplesPerSec,
71                                 uint32_t totalDelayMS,
72                                 int32_t clockDrift,
73                                 uint32_t micLevel,
74                                 bool keyPressed,
75                                 uint32_t& newMicLevel);
76
77     virtual int32_t NeedMorePlayData(uint32_t nSamples,
78                                      uint8_t nBytesPerSample,
79                                      uint8_t nChannels,
80                                      uint32_t samplesPerSec,
81                                      void* audioSamples,
82                                      uint32_t& nSamplesOut);
83
84     virtual int OnDataAvailable(const int voe_channels[],
85                                 int number_of_voe_channels,
86                                 const int16_t* audio_data,
87                                 int sample_rate,
88                                 int number_of_channels,
89                                 int number_of_frames,
90                                 int audio_delay_milliseconds,
91                                 int volume,
92                                 bool key_pressed,
93                                 bool need_audio_processing);
94
95     virtual void OnData(int voe_channel, const void* audio_data,
96                         int bits_per_sample, int sample_rate,
97                         int number_of_channels, int number_of_frames);
98
99     virtual void PushCaptureData(int voe_channel, const void* audio_data,
100                                  int bits_per_sample, int sample_rate,
101                                  int number_of_channels, int number_of_frames);
102
103     virtual void PullRenderData(int bits_per_sample, int sample_rate,
104                                 int number_of_channels, int number_of_frames,
105                                 void* audio_data);
106
107     // AudioDeviceObserver
108     virtual void OnErrorIsReported(ErrorCode error);
109     virtual void OnWarningIsReported(WarningCode warning);
110
111 protected:
112     VoEBaseImpl(voe::SharedData* shared);
113     virtual ~VoEBaseImpl();
114
115 private:
116     int32_t StartPlayout();
117     int32_t StopPlayout();
118     int32_t StartSend();
119     int32_t StopSend();
120     int32_t TerminateInternal();
121
122     // Helper function to process the recorded data with AudioProcessing Module,
123     // demultiplex the data to specific voe channels, encode and send to the
124     // network. When |number_of_VoE_channels| is 0, it will demultiplex the
125     // data to all the existing VoE channels.
126     // It returns new AGC microphone volume or 0 if no volume changes
127     // should be done.
128     int ProcessRecordedDataWithAPM(const int voe_channels[],
129                                    int number_of_voe_channels,
130                                    const void* audio_data,
131                                    uint32_t sample_rate,
132                                    uint8_t number_of_channels,
133                                    uint32_t number_of_frames,
134                                    uint32_t audio_delay_milliseconds,
135                                    int32_t clock_drift,
136                                    uint32_t volume,
137                                    bool key_pressed);
138
139     void GetPlayoutData(int sample_rate, int number_of_channels,
140                         int number_of_frames, bool feed_data_to_apm,
141                         void* audio_data);
142
143     int32_t AddBuildInfo(char* str) const;
144     int32_t AddVoEVersion(char* str) const;
145
146     // Initialize channel by setting Engine Information then initializing
147     // channel.
148     int InitializeChannel(voe::ChannelOwner* channel_owner);
149 #ifdef WEBRTC_EXTERNAL_TRANSPORT
150     int32_t AddExternalTransportBuild(char* str) const;
151 #endif
152 #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
153     int32_t AddExternalRecAndPlayoutBuild(char* str) const;
154 #endif
155     VoiceEngineObserver* _voiceEngineObserverPtr;
156     CriticalSectionWrapper& _callbackCritSect;
157
158     bool _voiceEngineObserver;
159     AudioFrame _audioFrame;
160     voe::SharedData* _shared;
161 };
162
163 }  // namespace webrtc
164
165 #endif  // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H