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