blob: 13183dd1eec63e223d23be302bb1bb7a2b279344 [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
26namespace webrtc
27{
28
29// VolumeControl
30enum { kMinVolumeLevel = 0 };
31enum { kMaxVolumeLevel = 255 };
32// Min scale factor for per-channel volume scaling
33const float kMinOutputVolumeScaling = 0.0f;
34// Max scale factor for per-channel volume scaling
35const float kMaxOutputVolumeScaling = 10.0f;
36// Min scale factor for output volume panning
37const float kMinOutputVolumePanning = 0.0f;
38// Max scale factor for output volume panning
39const float kMaxOutputVolumePanning = 1.0f;
40
41// DTMF
42enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
43enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
44enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
45enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
46enum { kMinTelephoneEventDuration = 100 };
47enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
48enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
49enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
50enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
51 // telephone events
52enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
53
54enum { kVoiceEngineMaxModuleVersionSize = 960 };
55
56// Base
57enum { kVoiceEngineVersionMaxMessageSize = 1024 };
58
59// Encryption
60// SRTP uses 30 bytes key length
61enum { kVoiceEngineMaxSrtpKeyLength = 30 };
62// SRTP minimum key/tag length for encryption level
63enum { kVoiceEngineMinSrtpEncryptLength = 16 };
64// SRTP maximum key/tag length for encryption level
65enum { kVoiceEngineMaxSrtpEncryptLength = 256 };
66// SRTP maximum key/tag length for authentication level,
67// HMAC SHA1 authentication type
68enum { kVoiceEngineMaxSrtpAuthSha1Length = 20 };
69// SRTP maximum tag length for authentication level,
70// null authentication type
71enum { kVoiceEngineMaxSrtpTagAuthNullLength = 12 };
72// SRTP maximum key length for authentication level,
73// null authentication type
74enum { kVoiceEngineMaxSrtpKeyAuthNullLength = 256 };
75
76// Audio processing
77enum { kVoiceEngineAudioProcessingDeviceSampleRateHz = 48000 };
78
79// Codec
80// Min init target rate for iSAC-wb
81enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
82// Max init target rate for iSAC-wb
83enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
84// Min init target rate for iSAC-swb
85enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
86// Max init target rate for iSAC-swb
87enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
88// Lowest max rate for iSAC-wb
89enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
90// Highest max rate for iSAC-wb
91enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
92// Lowest max rate for iSAC-swb
93enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
94// Highest max rate for iSAC-swb
95enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
96// Lowest max payload size for iSAC-wb
97enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
98// Highest max payload size for iSAC-wb
99enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
100// Lowest max payload size for iSAC-swb
101enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
102// Highest max payload size for iSAC-swb
103enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
104
105// VideoSync
106// Lowest minimum playout delay
107enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
108// Highest minimum playout delay
109enum { kVoiceEngineMaxMinPlayoutDelayMs = 1000 };
110
111// Network
112// Min packet-timeout time for received RTP packets
113enum { kVoiceEngineMinPacketTimeoutSec = 1 };
114// Max packet-timeout time for received RTP packets
115enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
116// Min sample time for dead-or-alive detection
117enum { kVoiceEngineMinSampleTimeSec = 1 };
118// Max sample time for dead-or-alive detection
119enum { kVoiceEngineMaxSampleTimeSec = 150 };
120
121// RTP/RTCP
122// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
123enum { kVoiceEngineMinRtpExtensionId = 1 };
124// Max 4-bit ID for RTP extension
125enum { kVoiceEngineMaxRtpExtensionId = 14 };
126
127} // namespace webrtc
128
129// TODO(andrew): we shouldn't be using the precompiler for this.
130// Use enums or bools as appropriate.
131#define WEBRTC_AUDIO_PROCESSING_OFF false
132
133#define WEBRTC_VOICE_ENGINE_HP_DEFAULT_STATE true
134 // AudioProcessing HP is ON
135#define WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
136 // AudioProcessing NS off
137#define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE true
138 // AudioProcessing AGC on
139#define WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
140 // AudioProcessing EC off
141#define WEBRTC_VOICE_ENGINE_VAD_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
142 // AudioProcessing off
143#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
144 // AudioProcessing RX AGC off
145#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
146 // AudioProcessing RX NS off
147#define WEBRTC_VOICE_ENGINE_RX_HP_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
148 // AudioProcessing RX High Pass Filter off
149
150#define WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE NoiseSuppression::kModerate
151 // AudioProcessing NS moderate suppression
152#define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE GainControl::kAdaptiveAnalog
153 // AudioProcessing AGC analog digital combined
154#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
189#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
190 #include <windows.h>
191 #include <stdio.h>
192 #define DEBUG_PRINT(...) \
193 { \
194 char msg[256]; \
195 sprintf(msg, __VA_ARGS__); \
196 OutputDebugStringA(msg); \
197 }
198#else
199 // special fix for visual 2003
200 #define DEBUG_PRINT(exp) ((void)0)
201#endif // defined(_DEBUG) && defined(_WIN32)
202
203#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
204
205// ----------------------------------------------------------------------------
206// Default Trace filter
207// ----------------------------------------------------------------------------
208
209#define WEBRTC_VOICE_ENGINE_DEFAULT_TRACE_FILTER \
210 kTraceStateInfo | kTraceWarning | kTraceError | kTraceCritical | \
211 kTraceApiCall
212
213// ----------------------------------------------------------------------------
214// Inline functions
215// ----------------------------------------------------------------------------
216
217namespace webrtc
218{
219
220inline int VoEId(const int veId, const int chId)
221{
222 if (chId == -1)
223 {
224 const int dummyChannel(99);
225 return (int) ((veId << 16) + dummyChannel);
226 }
227 return (int) ((veId << 16) + chId);
228}
229
230inline int VoEModuleId(const int veId, const int chId)
231{
232 return (int) ((veId << 16) + chId);
233}
234
235// Convert module ID to internal VoE channel ID
236inline int VoEChannelId(const int moduleId)
237{
238 return (int) (moduleId & 0xffff);
239}
240
241} // namespace webrtc
242
243// ----------------------------------------------------------------------------
244// Platform settings
245// ----------------------------------------------------------------------------
246
247// *** WINDOWS ***
248
249#if defined(_WIN32)
250
251 #pragma comment( lib, "winmm.lib" )
252
253 #ifndef WEBRTC_EXTERNAL_TRANSPORT
254 #pragma comment( lib, "ws2_32.lib" )
255 #endif
256
257// ----------------------------------------------------------------------------
258// Enumerators
259// ----------------------------------------------------------------------------
260
261namespace webrtc
262{
263// Max number of supported channels
264enum { kVoiceEngineMaxNumOfChannels = 32 };
265// Max number of channels which can be played out simultaneously
266enum { kVoiceEngineMaxNumOfActiveChannels = 16 };
267} // namespace webrtc
268
269// ----------------------------------------------------------------------------
270// Defines
271// ----------------------------------------------------------------------------
272
273 #include <windows.h>
274 #include <mmsystem.h> // timeGetTime
275
276 #define GET_TIME_IN_MS() ::timeGetTime()
277 #define SLEEP(x) ::Sleep(x)
278 // Comparison of two strings without regard to case
279 #define STR_CASE_CMP(x,y) ::_stricmp(x,y)
280 // Compares characters of two strings without regard to case
281 #define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
282
283// Default device for Windows PC
284 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
285 AudioDeviceModule::kDefaultCommunicationDevice
286
287#endif // #if (defined(_WIN32)
288
289// *** LINUX ***
290
291#ifdef WEBRTC_LINUX
292
293#include <pthread.h>
294#include <sys/types.h>
295#include <sys/socket.h>
296#include <netinet/in.h>
297#include <arpa/inet.h>
298#ifndef QNX
299 #include <linux/net.h>
300#ifndef ANDROID
301 #include <sys/soundcard.h>
302#endif // ANDROID
303#endif // QNX
304#include <stdio.h>
305#include <string.h>
306#include <stdlib.h>
307#include <errno.h>
308#include <sys/stat.h>
309#include <sys/ioctl.h>
310#include <unistd.h>
311#include <fcntl.h>
312#include <sched.h>
313#include <time.h>
314#include <sys/time.h>
315
316#define DWORD unsigned long int
317#define WINAPI
318#define LPVOID void *
319#define FALSE 0
320#define TRUE 1
321#define UINT unsigned int
322#define UCHAR unsigned char
323#define TCHAR char
324#ifdef QNX
325#define _stricmp stricmp
326#else
327#define _stricmp strcasecmp
328#endif
329#define GetLastError() errno
330#define WSAGetLastError() errno
331#define LPCTSTR const char*
332#define LPCSTR const char*
333#define wsprintf sprintf
334#define TEXT(a) a
335#define _ftprintf fprintf
336#define _tcslen strlen
337#define FAR
338#define __cdecl
339#define LPSOCKADDR struct sockaddr *
340
341namespace
342{
343 void Sleep(unsigned long x)
344 {
345 timespec t;
346 t.tv_sec = x/1000;
347 t.tv_nsec = (x-(x/1000)*1000)*1000000;
348 nanosleep(&t,NULL);
349 }
350
351 DWORD timeGetTime()
352 {
353 struct timeval tv;
354 struct timezone tz;
355 unsigned long val;
356
357 gettimeofday(&tv, &tz);
358 val= tv.tv_sec*1000+ tv.tv_usec/1000;
359 return(val);
360 }
361}
362
363#define SLEEP(x) ::Sleep(x)
364#define GET_TIME_IN_MS timeGetTime
365
366// Default device for Linux and Android
367#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
368
369#ifdef ANDROID
370
371// ----------------------------------------------------------------------------
372// Enumerators
373// ----------------------------------------------------------------------------
374
375namespace webrtc
376{
377 // Max number of supported channels
378 enum { kVoiceEngineMaxNumOfChannels = 2 };
379 // Max number of channels which can be played out simultaneously
380 enum { kVoiceEngineMaxNumOfActiveChannels = 2 };
381} // namespace webrtc
382
383// ----------------------------------------------------------------------------
384// Defines
385// ----------------------------------------------------------------------------
386
387 // Always excluded for Android builds
388 #undef WEBRTC_CODEC_ISAC
389 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
390 #undef WEBRTC_CONFERENCING
391 #undef WEBRTC_TYPING_DETECTION
392
393 // Default audio processing states
394 #undef WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE
395 #undef WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE
396 #undef WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE
397 #define WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
398 #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
399 #define WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
400
401 // Default audio processing modes
402 #undef WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE
403 #undef WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE
404 #define WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE \
405 NoiseSuppression::kModerate
406 #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE \
407 GainControl::kAdaptiveDigital
408
409 #define ANDROID_NOT_SUPPORTED(stat) \
410 stat.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, \
411 "API call not supported"); \
412 return -1;
413
414#else // LINUX PC
415// ----------------------------------------------------------------------------
416// Enumerators
417// ----------------------------------------------------------------------------
418
419namespace webrtc
420{
421 // Max number of supported channels
422 enum { kVoiceEngineMaxNumOfChannels = 32 };
423 // Max number of channels which can be played out simultaneously
424 enum { kVoiceEngineMaxNumOfActiveChannels = 16 };
425} // namespace webrtc
426
427// ----------------------------------------------------------------------------
428// Defines
429// ----------------------------------------------------------------------------
430
431 #define ANDROID_NOT_SUPPORTED(stat)
432
433#endif // ANDROID - LINUX PC
434
435#else
436#define ANDROID_NOT_SUPPORTED(stat)
437#endif // #ifdef WEBRTC_LINUX
438
439// *** WEBRTC_MAC ***
440// including iPhone
441
442#ifdef WEBRTC_MAC
443
444#include <pthread.h>
445#include <sys/types.h>
446#include <sys/socket.h>
447#include <netinet/in.h>
448#include <arpa/inet.h>
449#include <stdio.h>
450#include <string.h>
451#include <stdlib.h>
452#include <errno.h>
453#include <sys/stat.h>
454#include <unistd.h>
455#include <fcntl.h>
456#include <sched.h>
457#include <sys/time.h>
458#include <time.h>
459#include <AudioUnit/AudioUnit.h>
460#if !defined(WEBRTC_IOS)
461 #include <CoreServices/CoreServices.h>
462 #include <CoreAudio/CoreAudio.h>
463 #include <AudioToolbox/DefaultAudioOutput.h>
464 #include <AudioToolbox/AudioConverter.h>
465 #include <CoreAudio/HostTime.h>
466#endif
467
468#define DWORD unsigned long int
469#define WINAPI
470#define LPVOID void *
471#define FALSE 0
472#define TRUE 1
473#define SOCKADDR_IN struct sockaddr_in
474#define UINT unsigned int
475#define UCHAR unsigned char
476#define TCHAR char
477#define _stricmp strcasecmp
478#define GetLastError() errno
479#define WSAGetLastError() errno
480#define LPCTSTR const char*
481#define wsprintf sprintf
482#define TEXT(a) a
483#define _ftprintf fprintf
484#define _tcslen strlen
485#define FAR
486#define __cdecl
487#define LPSOCKADDR struct sockaddr *
488#define LPCSTR const char*
489#define ULONG unsigned long
490
491namespace
492{
493 void Sleep(unsigned long x)
494 {
495 timespec t;
496 t.tv_sec = x/1000;
497 t.tv_nsec = (x-(x/1000)*1000)*1000000;
498 nanosleep(&t,NULL);
499 }
500
501 DWORD WebRtcTimeGetTime()
502 {
503 struct timeval tv;
504 struct timezone tz;
505 unsigned long val;
506
507 gettimeofday(&tv, &tz);
508 val= tv.tv_sec*1000+ tv.tv_usec/1000;
509 return(val);
510 }
511}
512
513#define SLEEP(x) ::Sleep(x)
514#define GET_TIME_IN_MS WebRtcTimeGetTime
515
516// Default device for Mac and iPhone
517#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
518
519// iPhone specific
520#if defined(WEBRTC_IOS)
521
522// ----------------------------------------------------------------------------
523// Enumerators
524// ----------------------------------------------------------------------------
525
526namespace webrtc
527{
528 // Max number of supported channels
529 enum { kVoiceEngineMaxNumOfChannels = 2 };
530 // Max number of channels which can be played out simultaneously
531 enum { kVoiceEngineMaxNumOfActiveChannels = 2 };
532} // namespace webrtc
533
534// ----------------------------------------------------------------------------
535// Defines
536// ----------------------------------------------------------------------------
537
538 // Always excluded for iPhone builds
539 #undef WEBRTC_CODEC_ISAC
540 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
541
542 #undef WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE
543 #undef WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE
544 #undef WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE
545 #define WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
546 #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
547 #define WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE WEBRTC_AUDIO_PROCESSING_OFF
548
549 #undef WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE
550 #undef WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE
551 #define WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE \
552 NoiseSuppression::kModerate
553 #define WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE \
554 GainControl::kAdaptiveDigital
555
556 #define IPHONE_NOT_SUPPORTED(stat) \
557 stat.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, \
558 "API call not supported"); \
559 return -1;
560
561#else // Non-iPhone
562
563// ----------------------------------------------------------------------------
564// Enumerators
565// ----------------------------------------------------------------------------
566
567namespace webrtc
568{
569 // Max number of supported channels
570 enum { kVoiceEngineMaxNumOfChannels = 32 };
571 // Max number of channels which can be played out simultaneously
572 enum { kVoiceEngineMaxNumOfActiveChannels = 16 };
573} // namespace webrtc
574
575// ----------------------------------------------------------------------------
576// Defines
577// ----------------------------------------------------------------------------
578
579 #define IPHONE_NOT_SUPPORTED(stat)
580#endif
581
582#else
583#define IPHONE_NOT_SUPPORTED(stat)
584#endif // #ifdef WEBRTC_MAC
585
586
587
588#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H