blob: 8a3973a89413e02eca7a9257330c1b23e6a99ddb [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
kma@webrtc.orgde66b912012-02-01 18:39:44 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org956aa7e2013-05-21 13:52:32 +000014#include "webrtc/voice_engine/include/voe_base.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000016#include "webrtc/modules/interface/module_common_types.h"
17#include "webrtc/voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc
20{
21
22class ProcessThread;
23
tommi@webrtc.org851becd2012-04-04 14:57:19 +000024class VoEBaseImpl: public VoEBase,
niklase@google.com470e71d2011-07-07 08:21:25 +000025 public AudioTransport,
26 public AudioDeviceObserver
27{
28public:
niklase@google.com470e71d2011-07-07 08:21:25 +000029 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
30
31 virtual int DeRegisterVoiceEngineObserver();
32
andrew@webrtc.orgf0a90c32013-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 }
niklase@google.com470e71d2011-07-07 08:21:25 +000038
39 virtual int Terminate();
40
niklase@google.com470e71d2011-07-07 08:21:25 +000041 virtual int CreateChannel();
turaj@webrtc.org03f33702013-11-13 00:02:48 +000042 virtual int CreateChannel(const Config& config);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
44 virtual int DeleteChannel(int channel);
45
niklase@google.com470e71d2011-07-07 08:21:25 +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
58 virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode);
59
60 virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode);
61
niklase@google.com470e71d2011-07-07 08:21:25 +000062 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
xians@webrtc.orgc1e28032014-02-02 15:30:20 +000072 virtual AudioTransport* audio_transport() { return this; }
xians@webrtc.org07e51962014-01-29 13:54:02 +000073
niklase@google.com470e71d2011-07-07 08:21:25 +000074 // AudioTransport
pbos@webrtc.org6141e132013-04-09 10:09:10 +000075 virtual int32_t
henrika@webrtc.org907bc552012-03-09 08:59:19 +000076 RecordedDataIsAvailable(const void* audioSamples,
pbos@webrtc.org92135212013-05-14 08:31:39 +000077 uint32_t nSamples,
78 uint8_t nBytesPerSample,
79 uint8_t nChannels,
80 uint32_t samplesPerSec,
81 uint32_t totalDelayMS,
82 int32_t clockDrift,
andrew@webrtc.org27c69802014-02-18 20:24:56 +000083 uint32_t micLevel,
pbos@webrtc.org92135212013-05-14 08:31:39 +000084 bool keyPressed,
pbos@webrtc.org6141e132013-04-09 10:09:10 +000085 uint32_t& newMicLevel);
niklase@google.com470e71d2011-07-07 08:21:25 +000086
pbos@webrtc.org92135212013-05-14 08:31:39 +000087 virtual int32_t NeedMorePlayData(uint32_t nSamples,
88 uint8_t nBytesPerSample,
89 uint8_t nChannels,
90 uint32_t samplesPerSec,
pbos@webrtc.org6141e132013-04-09 10:09:10 +000091 void* audioSamples,
92 uint32_t& nSamplesOut);
niklase@google.com470e71d2011-07-07 08:21:25 +000093
xians@webrtc.org8fff1f02013-07-31 16:27:42 +000094 virtual int OnDataAvailable(const int voe_channels[],
xians@webrtc.org2f84afa2013-07-31 16:23:37 +000095 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,
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000101 int volume,
xians@webrtc.org2f84afa2013-07-31 16:23:37 +0000102 bool key_pressed,
103 bool need_audio_processing);
104
xians@webrtc.orgc1e28032014-02-02 15:30:20 +0000105 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
xians@webrtc.org56925312014-04-14 10:50:37 +0000109 virtual void PushCaptureData(int voe_channel, const void* audio_data,
110 int bits_per_sample, int sample_rate,
111 int number_of_channels, int number_of_frames);
112
113 virtual void PullRenderData(int bits_per_sample, int sample_rate,
114 int number_of_channels, int number_of_frames,
115 void* audio_data);
116
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 // AudioDeviceObserver
pbos@webrtc.org92135212013-05-14 08:31:39 +0000118 virtual void OnErrorIsReported(ErrorCode error);
119 virtual void OnWarningIsReported(WarningCode warning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
121protected:
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000122 VoEBaseImpl(voe::SharedData* shared);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 virtual ~VoEBaseImpl();
124
125private:
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000126 int32_t StartPlayout();
127 int32_t StopPlayout();
128 int32_t StartSend();
129 int32_t StopSend();
130 int32_t TerminateInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000132 // Helper function to process the recorded data with AudioProcessing Module,
133 // demultiplex the data to specific voe channels, encode and send to the
134 // network. When |number_of_VoE_channels| is 0, it will demultiplex the
135 // data to all the existing VoE channels.
136 // It returns new AGC microphone volume or 0 if no volume changes
137 // should be done.
138 int ProcessRecordedDataWithAPM(const int voe_channels[],
139 int number_of_voe_channels,
140 const void* audio_data,
141 uint32_t sample_rate,
142 uint8_t number_of_channels,
143 uint32_t number_of_frames,
144 uint32_t audio_delay_milliseconds,
145 int32_t clock_drift,
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000146 uint32_t volume,
xians@webrtc.org8fff1f02013-07-31 16:27:42 +0000147 bool key_pressed);
148
xians@webrtc.org56925312014-04-14 10:50:37 +0000149 void GetPlayoutData(int sample_rate, int number_of_channels,
150 int number_of_frames, bool feed_data_to_apm,
151 void* audio_data);
152
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000153 int32_t AddBuildInfo(char* str) const;
154 int32_t AddVoEVersion(char* str) const;
turaj@webrtc.org03f33702013-11-13 00:02:48 +0000155
156 // Initialize channel by setting Engine Information then initializing
157 // channel.
158 int InitializeChannel(voe::ChannelOwner* channel_owner);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000159#ifdef WEBRTC_EXTERNAL_TRANSPORT
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000160 int32_t AddExternalTransportBuild(char* str) const;
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000161#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000162#ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000163 int32_t AddExternalRecAndPlayoutBuild(char* str) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000164#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000165 VoiceEngineObserver* _voiceEngineObserverPtr;
166 CriticalSectionWrapper& _callbackCritSect;
167
168 bool _voiceEngineObserver;
kma@webrtc.orgde66b912012-02-01 18:39:44 +0000169 AudioFrame _audioFrame;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000170 voe::SharedData* _shared;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171};
172
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000173} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
175#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H