blob: 8e5b24fb60506089a2da7f13acb8e362d73bde6e [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
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +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
53enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
54
55enum { kVoiceEngineMaxModuleVersionSize = 960 };
56
57// Base
58enum { kVoiceEngineVersionMaxMessageSize = 1024 };
59
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000060// Audio processing
andrew@webrtc.org6316d172013-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
andrew@webrtc.org28ea6f82013-10-04 17:54:09 +000074const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000075
76// Codec
77// Min init target rate for iSAC-wb
78enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
79// Max init target rate for iSAC-wb
80enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
81// Min init target rate for iSAC-swb
82enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
83// Max init target rate for iSAC-swb
84enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
85// Lowest max rate for iSAC-wb
86enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
87// Highest max rate for iSAC-wb
88enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
89// Lowest max rate for iSAC-swb
90enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
91// Highest max rate for iSAC-swb
92enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
93// Lowest max payload size for iSAC-wb
94enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
95// Highest max payload size for iSAC-wb
96enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
97// Lowest max payload size for iSAC-swb
98enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
99// Highest max payload size for iSAC-swb
100enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
101
102// VideoSync
103// Lowest minimum playout delay
104enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
105// Highest minimum playout delay
niklas.enbom@webrtc.org99e89cd2013-01-17 22:25:49 +0000106enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000107
108// Network
109// Min packet-timeout time for received RTP packets
110enum { kVoiceEngineMinPacketTimeoutSec = 1 };
111// Max packet-timeout time for received RTP packets
112enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
113// Min sample time for dead-or-alive detection
114enum { kVoiceEngineMinSampleTimeSec = 1 };
115// Max sample time for dead-or-alive detection
116enum { kVoiceEngineMaxSampleTimeSec = 150 };
117
118// RTP/RTCP
119// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
120enum { kVoiceEngineMinRtpExtensionId = 1 };
121// Max 4-bit ID for RTP extension
122enum { kVoiceEngineMaxRtpExtensionId = 14 };
123
pbos@webrtc.org5ab7b932013-07-03 15:12:26 +0000124} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000125
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000126// ----------------------------------------------------------------------------
127// Build information macros
128// ----------------------------------------------------------------------------
129
130#if defined(_DEBUG)
131#define BUILDMODE "d"
132#elif defined(DEBUG)
133#define BUILDMODE "d"
134#elif defined(NDEBUG)
135#define BUILDMODE "r"
136#else
137#define BUILDMODE "?"
138#endif
139
140#define BUILDTIME __TIME__
141#define BUILDDATE __DATE__
142
143// Example: "Oct 10 2002 12:05:30 r"
144#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
145
146// ----------------------------------------------------------------------------
147// Macros
148// ----------------------------------------------------------------------------
149
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000150#define NOT_SUPPORTED(stat) \
151 LOG_F(LS_ERROR) << "not supported"; \
152 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
153 return -1;
154
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000155#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
156 #include <windows.h>
157 #include <stdio.h>
158 #define DEBUG_PRINT(...) \
159 { \
160 char msg[256]; \
161 sprintf(msg, __VA_ARGS__); \
162 OutputDebugStringA(msg); \
163 }
164#else
165 // special fix for visual 2003
166 #define DEBUG_PRINT(exp) ((void)0)
167#endif // defined(_DEBUG) && defined(_WIN32)
168
169#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
170
171// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000172// Inline functions
173// ----------------------------------------------------------------------------
174
175namespace webrtc
176{
177
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000178inline int VoEId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000179{
180 if (chId == -1)
181 {
182 const int dummyChannel(99);
183 return (int) ((veId << 16) + dummyChannel);
184 }
185 return (int) ((veId << 16) + chId);
186}
187
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000188inline int VoEModuleId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000189{
190 return (int) ((veId << 16) + chId);
191}
192
193// Convert module ID to internal VoE channel ID
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000194inline int VoEChannelId(int moduleId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000195{
196 return (int) (moduleId & 0xffff);
197}
198
pbos@webrtc.org5ab7b932013-07-03 15:12:26 +0000199} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000200
201// ----------------------------------------------------------------------------
202// Platform settings
203// ----------------------------------------------------------------------------
204
205// *** WINDOWS ***
206
207#if defined(_WIN32)
208
andrew@webrtc.org81c4d242013-09-09 17:50:10 +0000209 #include <windows.h>
210
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000211 #pragma comment( lib, "winmm.lib" )
212
213 #ifndef WEBRTC_EXTERNAL_TRANSPORT
214 #pragma comment( lib, "ws2_32.lib" )
215 #endif
216
217// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000218// Defines
219// ----------------------------------------------------------------------------
220
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000221// Default device for Windows PC
222 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
223 AudioDeviceModule::kDefaultCommunicationDevice
224
225#endif // #if (defined(_WIN32)
226
227// *** LINUX ***
228
229#ifdef WEBRTC_LINUX
230
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000231#include <arpa/inet.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000232#include <netinet/in.h>
233#include <pthread.h>
234#include <sys/socket.h>
235#include <sys/types.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000236#ifndef QNX
237 #include <linux/net.h>
238#ifndef ANDROID
239 #include <sys/soundcard.h>
240#endif // ANDROID
241#endif // QNX
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000242#include <errno.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000243#include <fcntl.h>
244#include <sched.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000245#include <stdio.h>
246#include <stdlib.h>
247#include <string.h>
248#include <sys/ioctl.h>
249#include <sys/stat.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000250#include <sys/time.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000251#include <time.h>
252#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000253
254#define DWORD unsigned long int
255#define WINAPI
256#define LPVOID void *
257#define FALSE 0
258#define TRUE 1
259#define UINT unsigned int
260#define UCHAR unsigned char
261#define TCHAR char
262#ifdef QNX
263#define _stricmp stricmp
264#else
265#define _stricmp strcasecmp
266#endif
267#define GetLastError() errno
268#define WSAGetLastError() errno
269#define LPCTSTR const char*
270#define LPCSTR const char*
271#define wsprintf sprintf
272#define TEXT(a) a
273#define _ftprintf fprintf
274#define _tcslen strlen
275#define FAR
276#define __cdecl
277#define LPSOCKADDR struct sockaddr *
278
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000279// Default device for Linux and Android
280#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
281
282#ifdef ANDROID
283
284// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000285// Defines
286// ----------------------------------------------------------------------------
287
288 // Always excluded for Android builds
289 #undef WEBRTC_CODEC_ISAC
290 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000291
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000292 #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000293
294#else // LINUX PC
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000295
296// ----------------------------------------------------------------------------
297// Defines
298// ----------------------------------------------------------------------------
299
300 #define ANDROID_NOT_SUPPORTED(stat)
301
302#endif // ANDROID - LINUX PC
303
304#else
305#define ANDROID_NOT_SUPPORTED(stat)
306#endif // #ifdef WEBRTC_LINUX
307
308// *** WEBRTC_MAC ***
309// including iPhone
310
311#ifdef WEBRTC_MAC
312
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000313#include <AudioUnit/AudioUnit.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000314#include <arpa/inet.h>
315#include <errno.h>
316#include <fcntl.h>
317#include <netinet/in.h>
318#include <pthread.h>
319#include <sched.h>
320#include <stdio.h>
321#include <stdlib.h>
322#include <string.h>
323#include <sys/socket.h>
324#include <sys/stat.h>
325#include <sys/time.h>
326#include <sys/types.h>
327#include <time.h>
328#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000329#if !defined(WEBRTC_IOS)
330 #include <CoreServices/CoreServices.h>
331 #include <CoreAudio/CoreAudio.h>
332 #include <AudioToolbox/DefaultAudioOutput.h>
333 #include <AudioToolbox/AudioConverter.h>
334 #include <CoreAudio/HostTime.h>
335#endif
336
337#define DWORD unsigned long int
338#define WINAPI
339#define LPVOID void *
340#define FALSE 0
341#define TRUE 1
342#define SOCKADDR_IN struct sockaddr_in
343#define UINT unsigned int
344#define UCHAR unsigned char
345#define TCHAR char
346#define _stricmp strcasecmp
347#define GetLastError() errno
348#define WSAGetLastError() errno
349#define LPCTSTR const char*
350#define wsprintf sprintf
351#define TEXT(a) a
352#define _ftprintf fprintf
353#define _tcslen strlen
354#define FAR
355#define __cdecl
356#define LPSOCKADDR struct sockaddr *
357#define LPCSTR const char*
358#define ULONG unsigned long
359
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000360// Default device for Mac and iPhone
361#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
362
363// iPhone specific
364#if defined(WEBRTC_IOS)
365
366// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000367// Defines
368// ----------------------------------------------------------------------------
369
370 // Always excluded for iPhone builds
371 #undef WEBRTC_CODEC_ISAC
372 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
373
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000374 #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000375
376#else // Non-iPhone
377
378// ----------------------------------------------------------------------------
379// Enumerators
380// ----------------------------------------------------------------------------
381
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000382// ----------------------------------------------------------------------------
383// Defines
384// ----------------------------------------------------------------------------
385
386 #define IPHONE_NOT_SUPPORTED(stat)
387#endif
388
389#else
390#define IPHONE_NOT_SUPPORTED(stat)
391#endif // #ifdef WEBRTC_MAC
392
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000393#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H