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