blob: 2a904c7d083788924f14946b8d3e86c13f9c7405 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org80124742012-03-08 17:54:24 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org1e7ed7a2013-02-05 21:23:39 +000019#include "webrtc/common_types.h"
20#include "webrtc/engine_configurations.h"
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000021#include "webrtc/modules/audio_processing/include/audio_processing.h"
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +000022#include "webrtc/system_wrappers/interface/logging.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24// ----------------------------------------------------------------------------
25// Enumerators
26// ----------------------------------------------------------------------------
27
andrew@webrtc.org4a6f62d2013-02-01 23:42:44 +000028namespace webrtc {
29
niklase@google.com470e71d2011-07-07 08:21:25 +000030// VolumeControl
31enum { kMinVolumeLevel = 0 };
32enum { kMaxVolumeLevel = 255 };
33// Min scale factor for per-channel volume scaling
34const float kMinOutputVolumeScaling = 0.0f;
35// Max scale factor for per-channel volume scaling
36const float kMaxOutputVolumeScaling = 10.0f;
37// Min scale factor for output volume panning
38const float kMinOutputVolumePanning = 0.0f;
39// Max scale factor for output volume panning
40const float kMaxOutputVolumePanning = 1.0f;
41
42// DTMF
43enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
44enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
45enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
46enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
47enum { kMinTelephoneEventDuration = 100 };
48enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
49enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
50enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
51enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
52 // telephone events
niklase@google.com470e71d2011-07-07 08:21:25 +000053enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
54
55enum { kVoiceEngineMaxModuleVersionSize = 960 };
56
57// Base
58enum { kVoiceEngineVersionMaxMessageSize = 1024 };
59
niklase@google.com470e71d2011-07-07 08:21:25 +000060// Audio processing
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000061const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
62const GainControl::Mode kDefaultAgcMode =
63#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
64 GainControl::kAdaptiveDigital;
65#else
66 GainControl::kAdaptiveAnalog;
67#endif
68const bool kDefaultAgcState =
69#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
70 false;
71#else
72 true;
73#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000074
75// Codec
76// Min init target rate for iSAC-wb
77enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
78// Max init target rate for iSAC-wb
79enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
80// Min init target rate for iSAC-swb
81enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
82// Max init target rate for iSAC-swb
83enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
84// Lowest max rate for iSAC-wb
85enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
86// Highest max rate for iSAC-wb
87enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
88// Lowest max rate for iSAC-swb
89enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
90// Highest max rate for iSAC-swb
91enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
92// Lowest max payload size for iSAC-wb
93enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
94// Highest max payload size for iSAC-wb
95enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
96// Lowest max payload size for iSAC-swb
97enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
98// Highest max payload size for iSAC-swb
99enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
100
101// VideoSync
102// Lowest minimum playout delay
103enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
104// Highest minimum playout delay
niklas.enbom@webrtc.org218c5422013-01-17 22:25:49 +0000105enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107// Network
108// Min packet-timeout time for received RTP packets
109enum { kVoiceEngineMinPacketTimeoutSec = 1 };
110// Max packet-timeout time for received RTP packets
111enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
112// Min sample time for dead-or-alive detection
113enum { kVoiceEngineMinSampleTimeSec = 1 };
114// Max sample time for dead-or-alive detection
115enum { kVoiceEngineMaxSampleTimeSec = 150 };
116
117// RTP/RTCP
118// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
119enum { kVoiceEngineMinRtpExtensionId = 1 };
120// Max 4-bit ID for RTP extension
121enum { kVoiceEngineMaxRtpExtensionId = 14 };
122
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000123} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000125// TODO(ajm): we shouldn't be using the precompiler for this.
andrew@webrtc.orgf4589162011-10-03 15:22:28 +0000126// Use enums or bools as appropriate.
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000127#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_STATE false
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 // AudioProcessing RX AGC off
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000129#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_STATE false
niklase@google.com470e71d2011-07-07 08:21:25 +0000130 // AudioProcessing RX NS off
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000131#define WEBRTC_VOICE_ENGINE_RX_HP_DEFAULT_STATE false
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 // AudioProcessing RX High Pass Filter off
133
niklase@google.com470e71d2011-07-07 08:21:25 +0000134#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_MODE GainControl::kAdaptiveDigital
135 // AudioProcessing AGC mode
andrew@webrtc.org80124742012-03-08 17:54:24 +0000136#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_MODE NoiseSuppression::kModerate
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 // AudioProcessing RX NS mode
138
139// Macros
140// Comparison of two strings without regard to case
141#define STR_CASE_CMP(x,y) ::_stricmp(x,y)
142// Compares characters of two strings without regard to case
143#define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
144
145// ----------------------------------------------------------------------------
146// Build information macros
147// ----------------------------------------------------------------------------
148
149#if defined(_DEBUG)
150#define BUILDMODE "d"
151#elif defined(DEBUG)
152#define BUILDMODE "d"
153#elif defined(NDEBUG)
154#define BUILDMODE "r"
155#else
156#define BUILDMODE "?"
157#endif
158
159#define BUILDTIME __TIME__
160#define BUILDDATE __DATE__
161
162// Example: "Oct 10 2002 12:05:30 r"
163#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
164
165// ----------------------------------------------------------------------------
166// Macros
167// ----------------------------------------------------------------------------
168
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000169#define NOT_SUPPORTED(stat) \
170 LOG_F(LS_ERROR) << "not supported"; \
171 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
172 return -1;
173
niklase@google.com470e71d2011-07-07 08:21:25 +0000174#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
175 #include <windows.h>
176 #include <stdio.h>
177 #define DEBUG_PRINT(...) \
178 { \
179 char msg[256]; \
180 sprintf(msg, __VA_ARGS__); \
181 OutputDebugStringA(msg); \
182 }
183#else
184 // special fix for visual 2003
185 #define DEBUG_PRINT(exp) ((void)0)
186#endif // defined(_DEBUG) && defined(_WIN32)
187
188#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
189
190// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000191// Inline functions
192// ----------------------------------------------------------------------------
193
194namespace webrtc
195{
196
pbos@webrtc.org92135212013-05-14 08:31:39 +0000197inline int VoEId(int veId, int chId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000198{
199 if (chId == -1)
200 {
201 const int dummyChannel(99);
202 return (int) ((veId << 16) + dummyChannel);
203 }
204 return (int) ((veId << 16) + chId);
205}
206
pbos@webrtc.org92135212013-05-14 08:31:39 +0000207inline int VoEModuleId(int veId, int chId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000208{
209 return (int) ((veId << 16) + chId);
210}
211
212// Convert module ID to internal VoE channel ID
pbos@webrtc.org92135212013-05-14 08:31:39 +0000213inline int VoEChannelId(int moduleId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000214{
215 return (int) (moduleId & 0xffff);
216}
217
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000218} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
220// ----------------------------------------------------------------------------
221// Platform settings
222// ----------------------------------------------------------------------------
223
224// *** WINDOWS ***
225
226#if defined(_WIN32)
227
228 #pragma comment( lib, "winmm.lib" )
229
230 #ifndef WEBRTC_EXTERNAL_TRANSPORT
231 #pragma comment( lib, "ws2_32.lib" )
232 #endif
233
234// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000235// Defines
236// ----------------------------------------------------------------------------
237
238 #include <windows.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 // Comparison of two strings without regard to case
241 #define STR_CASE_CMP(x,y) ::_stricmp(x,y)
242 // Compares characters of two strings without regard to case
243 #define STR_NCASE_CMP(x,y,n) ::_strnicmp(x,y,n)
244
245// Default device for Windows PC
246 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
247 AudioDeviceModule::kDefaultCommunicationDevice
248
249#endif // #if (defined(_WIN32)
250
251// *** LINUX ***
252
253#ifdef WEBRTC_LINUX
254
niklase@google.com470e71d2011-07-07 08:21:25 +0000255#include <arpa/inet.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000256#include <netinet/in.h>
257#include <pthread.h>
258#include <sys/socket.h>
259#include <sys/types.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000260#ifndef QNX
261 #include <linux/net.h>
262#ifndef ANDROID
263 #include <sys/soundcard.h>
264#endif // ANDROID
265#endif // QNX
niklase@google.com470e71d2011-07-07 08:21:25 +0000266#include <errno.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000267#include <fcntl.h>
268#include <sched.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000269#include <stdio.h>
270#include <stdlib.h>
271#include <string.h>
272#include <sys/ioctl.h>
273#include <sys/stat.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000274#include <sys/time.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000275#include <time.h>
276#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000277
278#define DWORD unsigned long int
279#define WINAPI
280#define LPVOID void *
281#define FALSE 0
282#define TRUE 1
283#define UINT unsigned int
284#define UCHAR unsigned char
285#define TCHAR char
286#ifdef QNX
287#define _stricmp stricmp
288#else
289#define _stricmp strcasecmp
290#endif
291#define GetLastError() errno
292#define WSAGetLastError() errno
293#define LPCTSTR const char*
294#define LPCSTR const char*
295#define wsprintf sprintf
296#define TEXT(a) a
297#define _ftprintf fprintf
298#define _tcslen strlen
299#define FAR
300#define __cdecl
301#define LPSOCKADDR struct sockaddr *
302
niklase@google.com470e71d2011-07-07 08:21:25 +0000303// Default device for Linux and Android
304#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
305
306#ifdef ANDROID
307
308// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000309// Defines
310// ----------------------------------------------------------------------------
311
312 // Always excluded for Android builds
313 #undef WEBRTC_CODEC_ISAC
314 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
niklase@google.com470e71d2011-07-07 08:21:25 +0000315
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000316 #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
318#else // LINUX PC
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
320// ----------------------------------------------------------------------------
321// Defines
322// ----------------------------------------------------------------------------
323
leozwang@webrtc.org26385772012-01-20 18:45:45 +0000324 #define ANDROID_NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
326#endif // ANDROID - LINUX PC
327
328#else
leozwang@webrtc.org26385772012-01-20 18:45:45 +0000329#define ANDROID_NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000330#endif // #ifdef WEBRTC_LINUX
331
332// *** WEBRTC_MAC ***
333// including iPhone
334
335#ifdef WEBRTC_MAC
336
niklase@google.com470e71d2011-07-07 08:21:25 +0000337#include <AudioUnit/AudioUnit.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000338#include <arpa/inet.h>
339#include <errno.h>
340#include <fcntl.h>
341#include <netinet/in.h>
342#include <pthread.h>
343#include <sched.h>
344#include <stdio.h>
345#include <stdlib.h>
346#include <string.h>
347#include <sys/socket.h>
348#include <sys/stat.h>
349#include <sys/time.h>
350#include <sys/types.h>
351#include <time.h>
352#include <unistd.h>
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000353#if !defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 #include <CoreServices/CoreServices.h>
355 #include <CoreAudio/CoreAudio.h>
356 #include <AudioToolbox/DefaultAudioOutput.h>
357 #include <AudioToolbox/AudioConverter.h>
358 #include <CoreAudio/HostTime.h>
359#endif
360
361#define DWORD unsigned long int
362#define WINAPI
363#define LPVOID void *
364#define FALSE 0
365#define TRUE 1
366#define SOCKADDR_IN struct sockaddr_in
367#define UINT unsigned int
368#define UCHAR unsigned char
369#define TCHAR char
370#define _stricmp strcasecmp
371#define GetLastError() errno
372#define WSAGetLastError() errno
373#define LPCTSTR const char*
374#define wsprintf sprintf
375#define TEXT(a) a
376#define _ftprintf fprintf
377#define _tcslen strlen
378#define FAR
379#define __cdecl
380#define LPSOCKADDR struct sockaddr *
381#define LPCSTR const char*
382#define ULONG unsigned long
383
niklase@google.com470e71d2011-07-07 08:21:25 +0000384// Default device for Mac and iPhone
385#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
386
387// iPhone specific
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000388#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
390// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000391// Defines
392// ----------------------------------------------------------------------------
393
394 // Always excluded for iPhone builds
395 #undef WEBRTC_CODEC_ISAC
396 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
397
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000398 #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
400#else // Non-iPhone
401
402// ----------------------------------------------------------------------------
403// Enumerators
404// ----------------------------------------------------------------------------
405
niklase@google.com470e71d2011-07-07 08:21:25 +0000406// ----------------------------------------------------------------------------
407// Defines
408// ----------------------------------------------------------------------------
409
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000410 #define IPHONE_NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000411#endif
412
413#else
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000414#define IPHONE_NOT_SUPPORTED(stat)
niklase@google.com470e71d2011-07-07 08:21:25 +0000415#endif // #ifdef WEBRTC_MAC
416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H