Line data Source code
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 : /*
12 : * This file contains common constants for VoiceEngine, as well as
13 : * platform specific settings and include files.
14 : */
15 :
16 : #ifndef WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
17 : #define WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
18 :
19 : #include "webrtc/common_types.h"
20 : #include "webrtc/modules/audio_processing/include/audio_processing.h"
21 : #include "webrtc/typedefs.h"
22 :
23 : // ----------------------------------------------------------------------------
24 : // Enumerators
25 : // ----------------------------------------------------------------------------
26 :
27 : namespace webrtc {
28 :
29 : // Internal buffer size required for mono audio, based on the highest sample
30 : // rate voice engine supports (10 ms of audio at 192 kHz).
31 : static const size_t kMaxMonoDataSizeSamples = 1920;
32 :
33 : // VolumeControl
34 : enum { kMinVolumeLevel = 0 };
35 : enum { kMaxVolumeLevel = 255 };
36 : // Min scale factor for per-channel volume scaling
37 : const float kMinOutputVolumeScaling = 0.0f;
38 : // Max scale factor for per-channel volume scaling
39 : const float kMaxOutputVolumeScaling = 10.0f;
40 : // Min scale factor for output volume panning
41 : const float kMinOutputVolumePanning = 0.0f;
42 : // Max scale factor for output volume panning
43 : const float kMaxOutputVolumePanning = 1.0f;
44 :
45 : // DTMF
46 : enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
47 : enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
48 : enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
49 : enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
50 : enum { kMinTelephoneEventDuration = 40 };
51 : enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
52 : enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
53 : enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
54 : enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
55 : // telephone events
56 : enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
57 :
58 : enum { kVoiceEngineMaxModuleVersionSize = 960 };
59 :
60 : // Audio processing
61 : const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
62 : const GainControl::Mode kDefaultAgcMode =
63 : #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_GONK)
64 : GainControl::kAdaptiveDigital;
65 : #else
66 : GainControl::kAdaptiveAnalog;
67 : #endif
68 : const bool kDefaultAgcState =
69 : #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_GONK)
70 : false;
71 : #else
72 : true;
73 : #endif
74 : const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
75 :
76 : // Codec
77 : // Min init target rate for iSAC-wb
78 : enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
79 : // Max init target rate for iSAC-wb
80 : enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
81 : // Min init target rate for iSAC-swb
82 : enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
83 : // Max init target rate for iSAC-swb
84 : enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
85 : // Lowest max rate for iSAC-wb
86 : enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
87 : // Highest max rate for iSAC-wb
88 : enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
89 : // Lowest max rate for iSAC-swb
90 : enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
91 : // Highest max rate for iSAC-swb
92 : enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
93 : // Lowest max payload size for iSAC-wb
94 : enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
95 : // Highest max payload size for iSAC-wb
96 : enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
97 : // Lowest max payload size for iSAC-swb
98 : enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
99 : // Highest max payload size for iSAC-swb
100 : enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
101 :
102 : // VideoSync
103 : // Lowest minimum playout delay
104 : enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
105 : // Highest minimum playout delay
106 : enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
107 :
108 : // Network
109 : // Min packet-timeout time for received RTP packets
110 : enum { kVoiceEngineMinPacketTimeoutSec = 1 };
111 : // Max packet-timeout time for received RTP packets
112 : enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
113 : // Min sample time for dead-or-alive detection
114 : enum { kVoiceEngineMinSampleTimeSec = 1 };
115 : // Max sample time for dead-or-alive detection
116 : enum { kVoiceEngineMaxSampleTimeSec = 150 };
117 :
118 : // RTP/RTCP
119 : // Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
120 : enum { kVoiceEngineMinRtpExtensionId = 1 };
121 : // Max 4-bit ID for RTP extension
122 : enum { kVoiceEngineMaxRtpExtensionId = 14 };
123 :
124 : } // namespace webrtc
125 :
126 : // ----------------------------------------------------------------------------
127 : // Macros
128 : // ----------------------------------------------------------------------------
129 :
130 : #define NOT_SUPPORTED(stat) \
131 : LOG_F(LS_ERROR) << "not supported"; \
132 : stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
133 : return -1;
134 :
135 : #if (!defined(NDEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
136 : #include <windows.h>
137 : #include <stdio.h>
138 : #define DEBUG_PRINT(...) \
139 : { \
140 : char msg[256]; \
141 : sprintf(msg, __VA_ARGS__); \
142 : OutputDebugStringA(msg); \
143 : }
144 : #else
145 : // special fix for visual 2003
146 : #define DEBUG_PRINT(exp) ((void)0)
147 : #endif // !defined(NDEBUG) && defined(_WIN32)
148 :
149 : #define CHECK_CHANNEL(channel) \
150 : if (CheckChannel(channel) == -1) \
151 : return -1;
152 :
153 : // ----------------------------------------------------------------------------
154 : // Inline functions
155 : // ----------------------------------------------------------------------------
156 :
157 : namespace webrtc {
158 :
159 0 : inline int VoEId(int veId, int chId) {
160 0 : if (chId == -1) {
161 0 : const int dummyChannel(99);
162 0 : return (int)((veId << 16) + dummyChannel);
163 : }
164 0 : return (int)((veId << 16) + chId);
165 : }
166 :
167 0 : inline int VoEModuleId(int veId, int chId) {
168 0 : return (int)((veId << 16) + chId);
169 : }
170 :
171 : // Convert module ID to internal VoE channel ID
172 0 : inline int VoEChannelId(int moduleId) {
173 0 : return (int)(moduleId & 0xffff);
174 : }
175 :
176 : } // namespace webrtc
177 :
178 : // ----------------------------------------------------------------------------
179 : // Platform settings
180 : // ----------------------------------------------------------------------------
181 :
182 : // *** WINDOWS ***
183 :
184 : #if defined(_WIN32)
185 :
186 : #include <windows.h>
187 :
188 : #pragma comment(lib, "winmm.lib")
189 :
190 : #ifndef WEBRTC_EXTERNAL_TRANSPORT
191 : #pragma comment(lib, "ws2_32.lib")
192 : #endif
193 :
194 : // ----------------------------------------------------------------------------
195 : // Defines
196 : // ----------------------------------------------------------------------------
197 :
198 : // Default device for Windows PC
199 : #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
200 : AudioDeviceModule::kDefaultCommunicationDevice
201 :
202 : #endif // #if (defined(_WIN32)
203 :
204 : // *** LINUX ***
205 :
206 : #ifdef WEBRTC_LINUX
207 :
208 : #include <arpa/inet.h>
209 : #include <netinet/in.h>
210 : #include <pthread.h>
211 : #include <sys/socket.h>
212 : #include <sys/types.h>
213 : #ifndef QNX
214 : #include <linux/net.h>
215 : #ifndef ANDROID
216 : #include <sys/soundcard.h>
217 : #endif // ANDROID
218 : #endif // QNX
219 : #include <errno.h>
220 : #include <fcntl.h>
221 : #include <sched.h>
222 : #include <stdio.h>
223 : #include <stdlib.h>
224 : #include <string.h>
225 : #include <sys/ioctl.h>
226 : #include <sys/stat.h>
227 : #include <sys/time.h>
228 : #include <time.h>
229 : #include <unistd.h>
230 :
231 : #define DWORD unsigned long int
232 : #define WINAPI
233 : #define LPVOID void *
234 : #define FALSE 0
235 : #define TRUE 1
236 : #define UINT unsigned int
237 : #define UCHAR unsigned char
238 : #define TCHAR char
239 : #ifdef QNX
240 : #define _stricmp stricmp
241 : #else
242 : #define _stricmp strcasecmp
243 : #endif
244 : #define GetLastError() errno
245 : #define WSAGetLastError() errno
246 : #define LPCTSTR const char *
247 : #define LPCSTR const char *
248 : #define wsprintf sprintf
249 : #define TEXT(a) a
250 : #define _ftprintf fprintf
251 : #define _tcslen strlen
252 : #define FAR
253 : #define __cdecl
254 : #define LPSOCKADDR struct sockaddr *
255 :
256 : // Default device for Linux and Android
257 : #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
258 :
259 : #endif // #ifdef WEBRTC_LINUX
260 :
261 : // *** WEBRTC_MAC ***
262 : // including iPhone
263 :
264 : #if defined(WEBRTC_BSD) || defined(WEBRTC_MAC)
265 :
266 : #if !defined(WEBRTC_BSD)
267 : #include <AudioUnit/AudioUnit.h>
268 : #endif
269 : #include <arpa/inet.h>
270 : #include <errno.h>
271 : #include <fcntl.h>
272 : #include <netinet/in.h>
273 : #include <pthread.h>
274 : #include <sched.h>
275 : #include <stdio.h>
276 : #include <stdlib.h>
277 : #include <string.h>
278 : #include <sys/socket.h>
279 : #include <sys/stat.h>
280 : #include <sys/time.h>
281 : #include <sys/types.h>
282 : #include <time.h>
283 : #include <unistd.h>
284 : #if !defined(WEBRTC_BSD) && !defined(WEBRTC_IOS)
285 : #include <CoreServices/CoreServices.h>
286 : #include <CoreAudio/CoreAudio.h>
287 : #include <AudioToolbox/DefaultAudioOutput.h>
288 : #include <AudioToolbox/AudioConverter.h>
289 : #include <CoreAudio/HostTime.h>
290 : #endif
291 :
292 : #define DWORD unsigned long int
293 : #define WINAPI
294 : #define LPVOID void *
295 : #define FALSE 0
296 : #define TRUE 1
297 : #define SOCKADDR_IN struct sockaddr_in
298 : #define UINT unsigned int
299 : #define UCHAR unsigned char
300 : #define TCHAR char
301 : #define _stricmp strcasecmp
302 : #define GetLastError() errno
303 : #define WSAGetLastError() errno
304 : #define LPCTSTR const char *
305 : #define wsprintf sprintf
306 : #define TEXT(a) a
307 : #define _ftprintf fprintf
308 : #define _tcslen strlen
309 : #define FAR
310 : #define __cdecl
311 : #define LPSOCKADDR struct sockaddr *
312 : #define LPCSTR const char *
313 : #define ULONG unsigned long
314 :
315 : // Default device for Mac and iPhone
316 : #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
317 : #endif // #if defined(WEBRTC_BSD) || defined(WEBRTC_MAC)
318 :
319 : #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
|