blob: aff1a2ed39002cc7219ab6aa6750626aa8b17bb4 [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
58 virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode);
59
60 virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode);
61
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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.org942ba532014-01-29 13:54:02 +000072 virtual void CaptureCallback(int voe_channel, const void* audio_data,
73 int bits_per_sample, int sample_rate,
74 int number_of_channels, int number_of_frames);
75
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000076 // AudioTransport
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000077 virtual int32_t
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000078 RecordedDataIsAvailable(const void* audioSamples,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000079 uint32_t nSamples,
80 uint8_t nBytesPerSample,
81 uint8_t nChannels,
82 uint32_t samplesPerSec,
83 uint32_t totalDelayMS,
84 int32_t clockDrift,
85 uint32_t currentMicLevel,
86 bool keyPressed,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000087 uint32_t& newMicLevel);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000088
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000089 virtual int32_t NeedMorePlayData(uint32_t nSamples,
90 uint8_t nBytesPerSample,
91 uint8_t nChannels,
92 uint32_t samplesPerSec,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000093 void* audioSamples,
94 uint32_t& nSamplesOut);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000095
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +000096 virtual int OnDataAvailable(const int voe_channels[],
xians@webrtc.org44f12392013-07-31 16:23:37 +000097 int number_of_voe_channels,
98 const int16_t* audio_data,
99 int sample_rate,
100 int number_of_channels,
101 int number_of_frames,
102 int audio_delay_milliseconds,
103 int current_volume,
104 bool key_pressed,
105 bool need_audio_processing);
106
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000107 // AudioDeviceObserver
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +0000108 virtual void OnErrorIsReported(ErrorCode error);
109 virtual void OnWarningIsReported(WarningCode warning);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000110
111protected:
112 VoEBaseImpl(voe::SharedData* shared);
113 virtual ~VoEBaseImpl();
114
115private:
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000116 int32_t StartPlayout();
117 int32_t StopPlayout();
118 int32_t StartSend();
119 int32_t StopSend();
120 int32_t TerminateInternal();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000121
xians@webrtc.org0e6fa8c2013-07-31 16:27:42 +0000122 // 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 current_volume,
137 bool key_pressed);
138
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000139 int32_t AddBuildInfo(char* str) const;
140 int32_t AddVoEVersion(char* str) const;
turaj@webrtc.orgb43ac9f2013-11-13 00:02:48 +0000141
142 // Initialize channel by setting Engine Information then initializing
143 // channel.
144 int InitializeChannel(voe::ChannelOwner* channel_owner);
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000145#ifdef WEBRTC_EXTERNAL_TRANSPORT
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000146 int32_t AddExternalTransportBuild(char* str) const;
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000147#endif
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000148#ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000149 int32_t AddExternalRecAndPlayoutBuild(char* str) const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000150#endif
151 VoiceEngineObserver* _voiceEngineObserverPtr;
152 CriticalSectionWrapper& _callbackCritSect;
153
154 bool _voiceEngineObserver;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +0000155 uint32_t _oldVoEMicLevel;
156 uint32_t _oldMicLevel;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000157 AudioFrame _audioFrame;
158 voe::SharedData* _shared;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000159};
160
pbos@webrtc.org3b89e102013-07-03 15:12:26 +0000161} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000162
163#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H