blob: 985ef5d8382d73a867cd2260edd0523a2db69edb [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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
pbos@webrtc.org471ae722013-05-21 13:52:32 +000014#include "webrtc/voice_engine/include/voe_base.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000015
pbos@webrtc.org471ae722013-05-21 13:52:32 +000016#include "webrtc/modules/interface/module_common_types.h"
17#include "webrtc/voice_engine/shared_data.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000018
19namespace webrtc
20{
21
22class ProcessThread;
23
24class VoEBaseImpl: public VoEBase,
25 public AudioTransport,
26 public AudioDeviceObserver
27{
28public:
29 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
30
31 virtual int DeRegisterVoiceEngineObserver();
32
andrew@webrtc.orgb79627b2013-03-05 01:12:49 +000033 virtual int Init(AudioDeviceModule* external_adm = NULL,
34 AudioProcessing* audioproc = NULL);
35 virtual AudioProcessing* audio_processing() {
36 return _shared->audio_processing();
37 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000038
39 virtual int Terminate();
40
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000041 virtual int CreateChannel();
turaj@webrtc.orgb43ac9f2013-11-13 00:02:48 +000042 virtual int CreateChannel(const Config& config);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000043
44 virtual int DeleteChannel(int channel);
45
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000046 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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000058 virtual int GetVersion(char version[1024]);
59
60 virtual int LastError();
61
xians@webrtc.org87c8b862014-02-02 15:30:20 +000062 virtual AudioTransport* audio_transport() { return this; }
xians@webrtc.org942ba532014-01-29 13:54:02 +000063
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000064 // AudioTransport
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000065 virtual int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000066 RecordedDataIsAvailable(const void* audioSamples,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000067 uint32_t nSamples,
68 uint8_t nBytesPerSample,
69 uint8_t nChannels,
70 uint32_t samplesPerSec,
71 uint32_t totalDelayMS,
72 int32_t clockDrift,
andrew@webrtc.orgad065d02014-02-18 20:24:56 +000073 uint32_t micLevel,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000074 bool keyPressed,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000075 uint32_t& newMicLevel);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000076
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000077 virtual int32_t NeedMorePlayData(uint32_t nSamples,
78 uint8_t nBytesPerSample,
79 uint8_t nChannels,
80 uint32_t samplesPerSec,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000081 void* audioSamples,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +000082 uint32_t& nSamplesOut,
wu@webrtc.org81f8df92014-06-05 20:34:08 +000083 int64_t* elapsed_time_ms,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +000084 int64_t* ntp_time_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000085
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +000086 virtual int OnDataAvailable(const int voe_channels[],
xians@webrtc.org44f12392013-07-31 16:23:37 +000087 int number_of_voe_channels,
88 const int16_t* audio_data,
89 int sample_rate,
90 int number_of_channels,
91 int number_of_frames,
92 int audio_delay_milliseconds,
andrew@webrtc.orgad065d02014-02-18 20:24:56 +000093 int volume,
xians@webrtc.org44f12392013-07-31 16:23:37 +000094 bool key_pressed,
95 bool need_audio_processing);
96
xians@webrtc.org87c8b862014-02-02 15:30:20 +000097 virtual void OnData(int voe_channel, const void* audio_data,
98 int bits_per_sample, int sample_rate,
99 int number_of_channels, int number_of_frames);
100
xians@webrtc.org91d88e12014-04-14 10:50:37 +0000101 virtual void PushCaptureData(int voe_channel, const void* audio_data,
102 int bits_per_sample, int sample_rate,
103 int number_of_channels, int number_of_frames);
104
105 virtual void PullRenderData(int bits_per_sample, int sample_rate,
106 int number_of_channels, int number_of_frames,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +0000107 void* audio_data,
wu@webrtc.org81f8df92014-06-05 20:34:08 +0000108 int64_t* elapsed_time_ms,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +0000109 int64_t* ntp_time_ms);
xians@webrtc.org91d88e12014-04-14 10:50:37 +0000110
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000111 // AudioDeviceObserver
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000112 virtual void OnErrorIsReported(ErrorCode error);
113 virtual void OnWarningIsReported(WarningCode warning);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000114
115protected:
116 VoEBaseImpl(voe::SharedData* shared);
117 virtual ~VoEBaseImpl();
118
119private:
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000120 int32_t StartPlayout();
121 int32_t StopPlayout();
122 int32_t StartSend();
123 int32_t StopSend();
124 int32_t TerminateInternal();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000125
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +0000126 // Helper function to process the recorded data with AudioProcessing Module,
127 // demultiplex the data to specific voe channels, encode and send to the
128 // network. When |number_of_VoE_channels| is 0, it will demultiplex the
129 // data to all the existing VoE channels.
130 // It returns new AGC microphone volume or 0 if no volume changes
131 // should be done.
132 int ProcessRecordedDataWithAPM(const int voe_channels[],
133 int number_of_voe_channels,
134 const void* audio_data,
135 uint32_t sample_rate,
136 uint8_t number_of_channels,
137 uint32_t number_of_frames,
138 uint32_t audio_delay_milliseconds,
139 int32_t clock_drift,
andrew@webrtc.orgad065d02014-02-18 20:24:56 +0000140 uint32_t volume,
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +0000141 bool key_pressed);
142
xians@webrtc.org91d88e12014-04-14 10:50:37 +0000143 void GetPlayoutData(int sample_rate, int number_of_channels,
144 int number_of_frames, bool feed_data_to_apm,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +0000145 void* audio_data,
wu@webrtc.org81f8df92014-06-05 20:34:08 +0000146 int64_t* elapsed_time_ms,
wu@webrtc.org22f69bd2014-05-19 17:39:11 +0000147 int64_t* ntp_time_ms);
xians@webrtc.org91d88e12014-04-14 10:50:37 +0000148
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000149 int32_t AddBuildInfo(char* str) const;
150 int32_t AddVoEVersion(char* str) const;
turaj@webrtc.orgb43ac9f2013-11-13 00:02:48 +0000151
152 // Initialize channel by setting Engine Information then initializing
153 // channel.
154 int InitializeChannel(voe::ChannelOwner* channel_owner);
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000155#ifdef WEBRTC_EXTERNAL_TRANSPORT
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000156 int32_t AddExternalTransportBuild(char* str) const;
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000157#endif
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000158 VoiceEngineObserver* _voiceEngineObserverPtr;
159 CriticalSectionWrapper& _callbackCritSect;
160
161 bool _voiceEngineObserver;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000162 AudioFrame _audioFrame;
163 voe::SharedData* _shared;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000164};
165
pbos@webrtc.org3b89e102013-07-03 15:12:26 +0000166} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000167
168#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H