blob: cb63940dfdb3086ee8916d6c7f1c738f9290f8d7 [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
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000063// Audio processing
andrew@webrtc.org6316d172013-03-05 01:12:49 +000064const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
65const GainControl::Mode kDefaultAgcMode =
66#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
67 GainControl::kAdaptiveDigital;
68#else
69 GainControl::kAdaptiveAnalog;
70#endif
71const bool kDefaultAgcState =
72#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
73 false;
74#else
75 true;
76#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000077
78// Codec
79// Min init target rate for iSAC-wb
80enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
81// Max init target rate for iSAC-wb
82enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
83// Min init target rate for iSAC-swb
84enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
85// Max init target rate for iSAC-swb
86enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
87// Lowest max rate for iSAC-wb
88enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
89// Highest max rate for iSAC-wb
90enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
91// Lowest max rate for iSAC-swb
92enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
93// Highest max rate for iSAC-swb
94enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
95// Lowest max payload size for iSAC-wb
96enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
97// Highest max payload size for iSAC-wb
98enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
99// Lowest max payload size for iSAC-swb
100enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
101// Highest max payload size for iSAC-swb
102enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
103
104// VideoSync
105// Lowest minimum playout delay
106enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
107// Highest minimum playout delay
niklas.enbom@webrtc.org99e89cd2013-01-17 22:25:49 +0000108enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000109
110// Network
111// Min packet-timeout time for received RTP packets
112enum { kVoiceEngineMinPacketTimeoutSec = 1 };
113// Max packet-timeout time for received RTP packets
114enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
115// Min sample time for dead-or-alive detection
116enum { kVoiceEngineMinSampleTimeSec = 1 };
117// Max sample time for dead-or-alive detection
118enum { kVoiceEngineMaxSampleTimeSec = 150 };
119
120// RTP/RTCP
121// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
122enum { kVoiceEngineMinRtpExtensionId = 1 };
123// Max 4-bit ID for RTP extension
124enum { kVoiceEngineMaxRtpExtensionId = 14 };
125
126} // namespace webrtc
127
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000128// TODO(ajm): we shouldn't be using the precompiler for this.
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000129// Use enums or bools as appropriate.
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000130#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000131 // AudioProcessing RX AGC off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000132#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000133 // AudioProcessing RX NS off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000134#define WEBRTC_VOICE_ENGINE_RX_HP_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000135 // AudioProcessing RX High Pass Filter off
136
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000137#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_MODE GainControl::kAdaptiveDigital
138 // AudioProcessing AGC mode
139#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_MODE NoiseSuppression::kModerate
140 // AudioProcessing RX NS mode
141
142// Macros
143// Comparison of two strings without regard to case
144#define STR_CASE_CMP(x,y) ::_stricmp(x,y)
145// Compares characters of two strings without regard to case
146#define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
147
148// ----------------------------------------------------------------------------
149// Build information macros
150// ----------------------------------------------------------------------------
151
152#if defined(_DEBUG)
153#define BUILDMODE "d"
154#elif defined(DEBUG)
155#define BUILDMODE "d"
156#elif defined(NDEBUG)
157#define BUILDMODE "r"
158#else
159#define BUILDMODE "?"
160#endif
161
162#define BUILDTIME __TIME__
163#define BUILDDATE __DATE__
164
165// Example: "Oct 10 2002 12:05:30 r"
166#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
167
168// ----------------------------------------------------------------------------
169// Macros
170// ----------------------------------------------------------------------------
171
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000172#define NOT_SUPPORTED(stat) \
173 LOG_F(LS_ERROR) << "not supported"; \
174 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
175 return -1;
176
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000177#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
178 #include <windows.h>
179 #include <stdio.h>
180 #define DEBUG_PRINT(...) \
181 { \
182 char msg[256]; \
183 sprintf(msg, __VA_ARGS__); \
184 OutputDebugStringA(msg); \
185 }
186#else
187 // special fix for visual 2003
188 #define DEBUG_PRINT(exp) ((void)0)
189#endif // defined(_DEBUG) && defined(_WIN32)
190
191#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
192
193// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000194// Inline functions
195// ----------------------------------------------------------------------------
196
197namespace webrtc
198{
199
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000200inline int VoEId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000201{
202 if (chId == -1)
203 {
204 const int dummyChannel(99);
205 return (int) ((veId << 16) + dummyChannel);
206 }
207 return (int) ((veId << 16) + chId);
208}
209
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000210inline int VoEModuleId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000211{
212 return (int) ((veId << 16) + chId);
213}
214
215// Convert module ID to internal VoE channel ID
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000216inline int VoEChannelId(int moduleId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000217{
218 return (int) (moduleId & 0xffff);
219}
220
221} // namespace webrtc
222
223// ----------------------------------------------------------------------------
224// Platform settings
225// ----------------------------------------------------------------------------
226
227// *** WINDOWS ***
228
229#if defined(_WIN32)
230
231 #pragma comment( lib, "winmm.lib" )
232
233 #ifndef WEBRTC_EXTERNAL_TRANSPORT
234 #pragma comment( lib, "ws2_32.lib" )
235 #endif
236
237// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000238// Defines
239// ----------------------------------------------------------------------------
240
241 #include <windows.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000242
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000243 // Comparison of two strings without regard to case
244 #define STR_CASE_CMP(x,y) ::_stricmp(x,y)
245 // Compares characters of two strings without regard to case
246 #define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
247
248// Default device for Windows PC
249 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
250 AudioDeviceModule::kDefaultCommunicationDevice
251
252#endif // #if (defined(_WIN32)
253
254// *** LINUX ***
255
256#ifdef WEBRTC_LINUX
257
258#include <pthread.h>
259#include <sys/types.h>
260#include <sys/socket.h>
261#include <netinet/in.h>
262#include <arpa/inet.h>
263#ifndef QNX
264 #include <linux/net.h>
265#ifndef ANDROID
266 #include <sys/soundcard.h>
267#endif // ANDROID
268#endif // QNX
269#include <stdio.h>
270#include <string.h>
271#include <stdlib.h>
272#include <errno.h>
273#include <sys/stat.h>
274#include <sys/ioctl.h>
275#include <unistd.h>
276#include <fcntl.h>
277#include <sched.h>
278#include <time.h>
279#include <sys/time.h>
280
281#define DWORD unsigned long int
282#define WINAPI
283#define LPVOID void *
284#define FALSE 0
285#define TRUE 1
286#define UINT unsigned int
287#define UCHAR unsigned char
288#define TCHAR char
289#ifdef QNX
290#define _stricmp stricmp
291#else
292#define _stricmp strcasecmp
293#endif
294#define GetLastError() errno
295#define WSAGetLastError() errno
296#define LPCTSTR const char*
297#define LPCSTR const char*
298#define wsprintf sprintf
299#define TEXT(a) a
300#define _ftprintf fprintf
301#define _tcslen strlen
302#define FAR
303#define __cdecl
304#define LPSOCKADDR struct sockaddr *
305
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000306// Default device for Linux and Android
307#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
308
309#ifdef ANDROID
310
311// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000312// Defines
313// ----------------------------------------------------------------------------
314
315 // Always excluded for Android builds
316 #undef WEBRTC_CODEC_ISAC
317 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
318 #undef WEBRTC_CONFERENCING
319 #undef WEBRTC_TYPING_DETECTION
320
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000321 #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000322
323#else // LINUX PC
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000324
325// ----------------------------------------------------------------------------
326// Defines
327// ----------------------------------------------------------------------------
328
329 #define ANDROID_NOT_SUPPORTED(stat)
330
331#endif // ANDROID - LINUX PC
332
333#else
334#define ANDROID_NOT_SUPPORTED(stat)
335#endif // #ifdef WEBRTC_LINUX
336
337// *** WEBRTC_MAC ***
338// including iPhone
339
340#ifdef WEBRTC_MAC
341
342#include <pthread.h>
343#include <sys/types.h>
344#include <sys/socket.h>
345#include <netinet/in.h>
346#include <arpa/inet.h>
347#include <stdio.h>
348#include <string.h>
349#include <stdlib.h>
350#include <errno.h>
351#include <sys/stat.h>
352#include <unistd.h>
353#include <fcntl.h>
354#include <sched.h>
355#include <sys/time.h>
356#include <time.h>
357#include <AudioUnit/AudioUnit.h>
358#if !defined(WEBRTC_IOS)
359 #include <CoreServices/CoreServices.h>
360 #include <CoreAudio/CoreAudio.h>
361 #include <AudioToolbox/DefaultAudioOutput.h>
362 #include <AudioToolbox/AudioConverter.h>
363 #include <CoreAudio/HostTime.h>
364#endif
365
366#define DWORD unsigned long int
367#define WINAPI
368#define LPVOID void *
369#define FALSE 0
370#define TRUE 1
371#define SOCKADDR_IN struct sockaddr_in
372#define UINT unsigned int
373#define UCHAR unsigned char
374#define TCHAR char
375#define _stricmp strcasecmp
376#define GetLastError() errno
377#define WSAGetLastError() errno
378#define LPCTSTR const char*
379#define wsprintf sprintf
380#define TEXT(a) a
381#define _ftprintf fprintf
382#define _tcslen strlen
383#define FAR
384#define __cdecl
385#define LPSOCKADDR struct sockaddr *
386#define LPCSTR const char*
387#define ULONG unsigned long
388
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000389// Default device for Mac and iPhone
390#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
391
392// iPhone specific
393#if defined(WEBRTC_IOS)
394
395// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000396// Defines
397// ----------------------------------------------------------------------------
398
399 // Always excluded for iPhone builds
400 #undef WEBRTC_CODEC_ISAC
401 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
402
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000403 #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000404
405#else // Non-iPhone
406
407// ----------------------------------------------------------------------------
408// Enumerators
409// ----------------------------------------------------------------------------
410
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000411// ----------------------------------------------------------------------------
412// Defines
413// ----------------------------------------------------------------------------
414
415 #define IPHONE_NOT_SUPPORTED(stat)
416#endif
417
418#else
419#define IPHONE_NOT_SUPPORTED(stat)
420#endif // #ifdef WEBRTC_MAC
421
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000422#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H