blob: e5c9af9dce268cb7cf6ffc2648fdcf559a63962e [file] [log] [blame]
andrew@webrtc.orga7b57da2012-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/*
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
andrew@webrtc.org4484b832013-02-05 21:23:39 +000019#include "webrtc/common_types.h"
20#include "webrtc/engine_configurations.h"
andrew@webrtc.org6316d172013-03-05 01:12:49 +000021#include "webrtc/modules/audio_processing/include/audio_processing.h"
andrew@webrtc.org4484b832013-02-05 21:23:39 +000022#include "webrtc/system_wrappers/interface/logging.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000023
24// ----------------------------------------------------------------------------
25// Enumerators
26// ----------------------------------------------------------------------------
27
andrew@webrtc.org48bfaa82013-02-01 23:42:44 +000028namespace webrtc {
29
30// TODO(ajm): There's not really a reason for this limitation. Remove it.
31enum { kVoiceEngineMaxNumChannels = 100 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000032
33// VolumeControl
34enum { kMinVolumeLevel = 0 };
35enum { kMaxVolumeLevel = 255 };
36// Min scale factor for per-channel volume scaling
37const float kMinOutputVolumeScaling = 0.0f;
38// Max scale factor for per-channel volume scaling
39const float kMaxOutputVolumeScaling = 10.0f;
40// Min scale factor for output volume panning
41const float kMinOutputVolumePanning = 0.0f;
42// Max scale factor for output volume panning
43const float kMaxOutputVolumePanning = 1.0f;
44
45// DTMF
46enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
47enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
48enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
49enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
50enum { kMinTelephoneEventDuration = 100 };
51enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
52enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
53enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
54enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
55 // telephone events
56enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
57
58enum { kVoiceEngineMaxModuleVersionSize = 960 };
59
60// Base
61enum { kVoiceEngineVersionMaxMessageSize = 1024 };
62
63// Encryption
64// SRTP uses 30 bytes key length
65enum { kVoiceEngineMaxSrtpKeyLength = 30 };
66// SRTP minimum key/tag length for encryption level
67enum { kVoiceEngineMinSrtpEncryptLength = 16 };
68// SRTP maximum key/tag length for encryption level
69enum { kVoiceEngineMaxSrtpEncryptLength = 256 };
70// SRTP maximum key/tag length for authentication level,
71// HMAC SHA1 authentication type
72enum { kVoiceEngineMaxSrtpAuthSha1Length = 20 };
73// SRTP maximum tag length for authentication level,
74// null authentication type
75enum { kVoiceEngineMaxSrtpTagAuthNullLength = 12 };
76// SRTP maximum key length for authentication level,
77// null authentication type
78enum { kVoiceEngineMaxSrtpKeyAuthNullLength = 256 };
79
80// Audio processing
andrew@webrtc.org6316d172013-03-05 01:12:49 +000081const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
82const GainControl::Mode kDefaultAgcMode =
83#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
84 GainControl::kAdaptiveDigital;
85#else
86 GainControl::kAdaptiveAnalog;
87#endif
88const bool kDefaultAgcState =
89#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
90 false;
91#else
92 true;
93#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000094
95// Codec
96// Min init target rate for iSAC-wb
97enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
98// Max init target rate for iSAC-wb
99enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
100// Min init target rate for iSAC-swb
101enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
102// Max init target rate for iSAC-swb
103enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
104// Lowest max rate for iSAC-wb
105enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
106// Highest max rate for iSAC-wb
107enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
108// Lowest max rate for iSAC-swb
109enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
110// Highest max rate for iSAC-swb
111enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
112// Lowest max payload size for iSAC-wb
113enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
114// Highest max payload size for iSAC-wb
115enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
116// Lowest max payload size for iSAC-swb
117enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
118// Highest max payload size for iSAC-swb
119enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
120
121// VideoSync
122// Lowest minimum playout delay
123enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
124// Highest minimum playout delay
niklas.enbom@webrtc.org99e89cd2013-01-17 22:25:49 +0000125enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000126
127// Network
128// Min packet-timeout time for received RTP packets
129enum { kVoiceEngineMinPacketTimeoutSec = 1 };
130// Max packet-timeout time for received RTP packets
131enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
132// Min sample time for dead-or-alive detection
133enum { kVoiceEngineMinSampleTimeSec = 1 };
134// Max sample time for dead-or-alive detection
135enum { kVoiceEngineMaxSampleTimeSec = 150 };
136
137// RTP/RTCP
138// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
139enum { kVoiceEngineMinRtpExtensionId = 1 };
140// Max 4-bit ID for RTP extension
141enum { kVoiceEngineMaxRtpExtensionId = 14 };
142
143} // namespace webrtc
144
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000145// TODO(ajm): we shouldn't be using the precompiler for this.
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000146// Use enums or bools as appropriate.
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000147#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000148 // AudioProcessing RX AGC off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000149#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000150 // AudioProcessing RX NS off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000151#define WEBRTC_VOICE_ENGINE_RX_HP_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000152 // AudioProcessing RX High Pass Filter off
153
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000154#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_MODE GainControl::kAdaptiveDigital
155 // AudioProcessing AGC mode
156#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_MODE NoiseSuppression::kModerate
157 // AudioProcessing RX NS mode
158
159// Macros
160// Comparison of two strings without regard to case
161#define STR_CASE_CMP(x,y) ::_stricmp(x,y)
162// Compares characters of two strings without regard to case
163#define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
164
165// ----------------------------------------------------------------------------
166// Build information macros
167// ----------------------------------------------------------------------------
168
169#if defined(_DEBUG)
170#define BUILDMODE "d"
171#elif defined(DEBUG)
172#define BUILDMODE "d"
173#elif defined(NDEBUG)
174#define BUILDMODE "r"
175#else
176#define BUILDMODE "?"
177#endif
178
179#define BUILDTIME __TIME__
180#define BUILDDATE __DATE__
181
182// Example: "Oct 10 2002 12:05:30 r"
183#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
184
185// ----------------------------------------------------------------------------
186// Macros
187// ----------------------------------------------------------------------------
188
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000189#define NOT_SUPPORTED(stat) \
190 LOG_F(LS_ERROR) << "not supported"; \
191 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
192 return -1;
193
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000194#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
195 #include <windows.h>
196 #include <stdio.h>
197 #define DEBUG_PRINT(...) \
198 { \
199 char msg[256]; \
200 sprintf(msg, __VA_ARGS__); \
201 OutputDebugStringA(msg); \
202 }
203#else
204 // special fix for visual 2003
205 #define DEBUG_PRINT(exp) ((void)0)
206#endif // defined(_DEBUG) && defined(_WIN32)
207
208#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
209
210// ----------------------------------------------------------------------------
211// Default Trace filter
212// ----------------------------------------------------------------------------
213
214#define WEBRTC_VOICE_ENGINE_DEFAULT_TRACE_FILTER \
215 kTraceStateInfo | kTraceWarning | kTraceError | kTraceCritical | \
216 kTraceApiCall
217
218// ----------------------------------------------------------------------------
219// Inline functions
220// ----------------------------------------------------------------------------
221
222namespace webrtc
223{
224
225inline int VoEId(const int veId, const int chId)
226{
227 if (chId == -1)
228 {
229 const int dummyChannel(99);
230 return (int) ((veId << 16) + dummyChannel);
231 }
232 return (int) ((veId << 16) + chId);
233}
234
235inline int VoEModuleId(const int veId, const int chId)
236{
237 return (int) ((veId << 16) + chId);
238}
239
240// Convert module ID to internal VoE channel ID
241inline int VoEChannelId(const int moduleId)
242{
243 return (int) (moduleId & 0xffff);
244}
245
246} // namespace webrtc
247
248// ----------------------------------------------------------------------------
249// Platform settings
250// ----------------------------------------------------------------------------
251
252// *** WINDOWS ***
253
254#if defined(_WIN32)
255
256 #pragma comment( lib, "winmm.lib" )
257
258 #ifndef WEBRTC_EXTERNAL_TRANSPORT
259 #pragma comment( lib, "ws2_32.lib" )
260 #endif
261
262// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000263// Defines
264// ----------------------------------------------------------------------------
265
266 #include <windows.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000267
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000268 // Comparison of two strings without regard to case
269 #define STR_CASE_CMP(x,y) ::_stricmp(x,y)
270 // Compares characters of two strings without regard to case
271 #define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
272
273// Default device for Windows PC
274 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
275 AudioDeviceModule::kDefaultCommunicationDevice
276
277#endif // #if (defined(_WIN32)
278
279// *** LINUX ***
280
281#ifdef WEBRTC_LINUX
282
283#include <pthread.h>
284#include <sys/types.h>
285#include <sys/socket.h>
286#include <netinet/in.h>
287#include <arpa/inet.h>
288#ifndef QNX
289 #include <linux/net.h>
290#ifndef ANDROID
291 #include <sys/soundcard.h>
292#endif // ANDROID
293#endif // QNX
294#include <stdio.h>
295#include <string.h>
296#include <stdlib.h>
297#include <errno.h>
298#include <sys/stat.h>
299#include <sys/ioctl.h>
300#include <unistd.h>
301#include <fcntl.h>
302#include <sched.h>
303#include <time.h>
304#include <sys/time.h>
305
306#define DWORD unsigned long int
307#define WINAPI
308#define LPVOID void *
309#define FALSE 0
310#define TRUE 1
311#define UINT unsigned int
312#define UCHAR unsigned char
313#define TCHAR char
314#ifdef QNX
315#define _stricmp stricmp
316#else
317#define _stricmp strcasecmp
318#endif
319#define GetLastError() errno
320#define WSAGetLastError() errno
321#define LPCTSTR const char*
322#define LPCSTR const char*
323#define wsprintf sprintf
324#define TEXT(a) a
325#define _ftprintf fprintf
326#define _tcslen strlen
327#define FAR
328#define __cdecl
329#define LPSOCKADDR struct sockaddr *
330
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000331// Default device for Linux and Android
332#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
333
334#ifdef ANDROID
335
336// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000337// Defines
338// ----------------------------------------------------------------------------
339
340 // Always excluded for Android builds
341 #undef WEBRTC_CODEC_ISAC
342 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
343 #undef WEBRTC_CONFERENCING
344 #undef WEBRTC_TYPING_DETECTION
345
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000346 #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000347
348#else // LINUX PC
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000349
350// ----------------------------------------------------------------------------
351// Defines
352// ----------------------------------------------------------------------------
353
354 #define ANDROID_NOT_SUPPORTED(stat)
355
356#endif // ANDROID - LINUX PC
357
358#else
359#define ANDROID_NOT_SUPPORTED(stat)
360#endif // #ifdef WEBRTC_LINUX
361
362// *** WEBRTC_MAC ***
363// including iPhone
364
365#ifdef WEBRTC_MAC
366
367#include <pthread.h>
368#include <sys/types.h>
369#include <sys/socket.h>
370#include <netinet/in.h>
371#include <arpa/inet.h>
372#include <stdio.h>
373#include <string.h>
374#include <stdlib.h>
375#include <errno.h>
376#include <sys/stat.h>
377#include <unistd.h>
378#include <fcntl.h>
379#include <sched.h>
380#include <sys/time.h>
381#include <time.h>
382#include <AudioUnit/AudioUnit.h>
383#if !defined(WEBRTC_IOS)
384 #include <CoreServices/CoreServices.h>
385 #include <CoreAudio/CoreAudio.h>
386 #include <AudioToolbox/DefaultAudioOutput.h>
387 #include <AudioToolbox/AudioConverter.h>
388 #include <CoreAudio/HostTime.h>
389#endif
390
391#define DWORD unsigned long int
392#define WINAPI
393#define LPVOID void *
394#define FALSE 0
395#define TRUE 1
396#define SOCKADDR_IN struct sockaddr_in
397#define UINT unsigned int
398#define UCHAR unsigned char
399#define TCHAR char
400#define _stricmp strcasecmp
401#define GetLastError() errno
402#define WSAGetLastError() errno
403#define LPCTSTR const char*
404#define wsprintf sprintf
405#define TEXT(a) a
406#define _ftprintf fprintf
407#define _tcslen strlen
408#define FAR
409#define __cdecl
410#define LPSOCKADDR struct sockaddr *
411#define LPCSTR const char*
412#define ULONG unsigned long
413
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000414// Default device for Mac and iPhone
415#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
416
417// iPhone specific
418#if defined(WEBRTC_IOS)
419
420// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000421// Defines
422// ----------------------------------------------------------------------------
423
424 // Always excluded for iPhone builds
425 #undef WEBRTC_CODEC_ISAC
426 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
427
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000428 #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000429
430#else // Non-iPhone
431
432// ----------------------------------------------------------------------------
433// Enumerators
434// ----------------------------------------------------------------------------
435
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000436// ----------------------------------------------------------------------------
437// Defines
438// ----------------------------------------------------------------------------
439
440 #define IPHONE_NOT_SUPPORTED(stat)
441#endif
442
443#else
444#define IPHONE_NOT_SUPPORTED(stat)
445#endif // #ifdef WEBRTC_MAC
446
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000447#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H