blob: 42851d444b39f05c2b3f4b0a0ee842f4d923d266 [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.orga7b57da2012-10-22 18:19:23 +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.org99e89cd2013-01-17 22:25:49 +0000105enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +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.org5ab7b932013-07-03 15:12:26 +0000123} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000124
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000125// TODO(ajm): we shouldn't be using the precompiler for this.
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000126// Use enums or bools as appropriate.
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000127#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000128 // AudioProcessing RX AGC off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000129#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000130 // AudioProcessing RX NS off
andrew@webrtc.org6316d172013-03-05 01:12:49 +0000131#define WEBRTC_VOICE_ENGINE_RX_HP_DEFAULT_STATE false
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000132 // AudioProcessing RX High Pass Filter off
133
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000134#define WEBRTC_VOICE_ENGINE_RX_AGC_DEFAULT_MODE GainControl::kAdaptiveDigital
135 // AudioProcessing AGC mode
136#define WEBRTC_VOICE_ENGINE_RX_NS_DEFAULT_MODE NoiseSuppression::kModerate
137 // AudioProcessing RX NS mode
138
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000139// ----------------------------------------------------------------------------
140// Build information macros
141// ----------------------------------------------------------------------------
142
143#if defined(_DEBUG)
144#define BUILDMODE "d"
145#elif defined(DEBUG)
146#define BUILDMODE "d"
147#elif defined(NDEBUG)
148#define BUILDMODE "r"
149#else
150#define BUILDMODE "?"
151#endif
152
153#define BUILDTIME __TIME__
154#define BUILDDATE __DATE__
155
156// Example: "Oct 10 2002 12:05:30 r"
157#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
158
159// ----------------------------------------------------------------------------
160// Macros
161// ----------------------------------------------------------------------------
162
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000163#define NOT_SUPPORTED(stat) \
164 LOG_F(LS_ERROR) << "not supported"; \
165 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
166 return -1;
167
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000168#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
169 #include <windows.h>
170 #include <stdio.h>
171 #define DEBUG_PRINT(...) \
172 { \
173 char msg[256]; \
174 sprintf(msg, __VA_ARGS__); \
175 OutputDebugStringA(msg); \
176 }
177#else
178 // special fix for visual 2003
179 #define DEBUG_PRINT(exp) ((void)0)
180#endif // defined(_DEBUG) && defined(_WIN32)
181
182#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
183
184// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000185// Inline functions
186// ----------------------------------------------------------------------------
187
188namespace webrtc
189{
190
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000191inline int VoEId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000192{
193 if (chId == -1)
194 {
195 const int dummyChannel(99);
196 return (int) ((veId << 16) + dummyChannel);
197 }
198 return (int) ((veId << 16) + chId);
199}
200
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000201inline int VoEModuleId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000202{
203 return (int) ((veId << 16) + chId);
204}
205
206// Convert module ID to internal VoE channel ID
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000207inline int VoEChannelId(int moduleId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000208{
209 return (int) (moduleId & 0xffff);
210}
211
pbos@webrtc.org5ab7b932013-07-03 15:12:26 +0000212} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000213
214// ----------------------------------------------------------------------------
215// Platform settings
216// ----------------------------------------------------------------------------
217
218// *** WINDOWS ***
219
220#if defined(_WIN32)
221
andrew@webrtc.org81c4d242013-09-09 17:50:10 +0000222 #include <windows.h>
223
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000224 #pragma comment( lib, "winmm.lib" )
225
226 #ifndef WEBRTC_EXTERNAL_TRANSPORT
227 #pragma comment( lib, "ws2_32.lib" )
228 #endif
229
230// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000231// Defines
232// ----------------------------------------------------------------------------
233
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000234// Default device for Windows PC
235 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
236 AudioDeviceModule::kDefaultCommunicationDevice
237
238#endif // #if (defined(_WIN32)
239
240// *** LINUX ***
241
242#ifdef WEBRTC_LINUX
243
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000244#include <arpa/inet.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000245#include <netinet/in.h>
246#include <pthread.h>
247#include <sys/socket.h>
248#include <sys/types.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000249#ifndef QNX
250 #include <linux/net.h>
251#ifndef ANDROID
252 #include <sys/soundcard.h>
253#endif // ANDROID
254#endif // QNX
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000255#include <errno.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000256#include <fcntl.h>
257#include <sched.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000258#include <stdio.h>
259#include <stdlib.h>
260#include <string.h>
261#include <sys/ioctl.h>
262#include <sys/stat.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000263#include <sys/time.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000264#include <time.h>
265#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000266
267#define DWORD unsigned long int
268#define WINAPI
269#define LPVOID void *
270#define FALSE 0
271#define TRUE 1
272#define UINT unsigned int
273#define UCHAR unsigned char
274#define TCHAR char
275#ifdef QNX
276#define _stricmp stricmp
277#else
278#define _stricmp strcasecmp
279#endif
280#define GetLastError() errno
281#define WSAGetLastError() errno
282#define LPCTSTR const char*
283#define LPCSTR const char*
284#define wsprintf sprintf
285#define TEXT(a) a
286#define _ftprintf fprintf
287#define _tcslen strlen
288#define FAR
289#define __cdecl
290#define LPSOCKADDR struct sockaddr *
291
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000292// Default device for Linux and Android
293#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
294
295#ifdef ANDROID
296
297// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000298// Defines
299// ----------------------------------------------------------------------------
300
301 // Always excluded for Android builds
302 #undef WEBRTC_CODEC_ISAC
303 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000304
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000305 #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000306
307#else // LINUX PC
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000308
309// ----------------------------------------------------------------------------
310// Defines
311// ----------------------------------------------------------------------------
312
313 #define ANDROID_NOT_SUPPORTED(stat)
314
315#endif // ANDROID - LINUX PC
316
317#else
318#define ANDROID_NOT_SUPPORTED(stat)
319#endif // #ifdef WEBRTC_LINUX
320
321// *** WEBRTC_MAC ***
322// including iPhone
323
324#ifdef WEBRTC_MAC
325
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000326#include <AudioUnit/AudioUnit.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000327#include <arpa/inet.h>
328#include <errno.h>
329#include <fcntl.h>
330#include <netinet/in.h>
331#include <pthread.h>
332#include <sched.h>
333#include <stdio.h>
334#include <stdlib.h>
335#include <string.h>
336#include <sys/socket.h>
337#include <sys/stat.h>
338#include <sys/time.h>
339#include <sys/types.h>
340#include <time.h>
341#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000342#if !defined(WEBRTC_IOS)
343 #include <CoreServices/CoreServices.h>
344 #include <CoreAudio/CoreAudio.h>
345 #include <AudioToolbox/DefaultAudioOutput.h>
346 #include <AudioToolbox/AudioConverter.h>
347 #include <CoreAudio/HostTime.h>
348#endif
349
350#define DWORD unsigned long int
351#define WINAPI
352#define LPVOID void *
353#define FALSE 0
354#define TRUE 1
355#define SOCKADDR_IN struct sockaddr_in
356#define UINT unsigned int
357#define UCHAR unsigned char
358#define TCHAR char
359#define _stricmp strcasecmp
360#define GetLastError() errno
361#define WSAGetLastError() errno
362#define LPCTSTR const char*
363#define wsprintf sprintf
364#define TEXT(a) a
365#define _ftprintf fprintf
366#define _tcslen strlen
367#define FAR
368#define __cdecl
369#define LPSOCKADDR struct sockaddr *
370#define LPCSTR const char*
371#define ULONG unsigned long
372
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000373// Default device for Mac and iPhone
374#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
375
376// iPhone specific
377#if defined(WEBRTC_IOS)
378
379// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000380// Defines
381// ----------------------------------------------------------------------------
382
383 // Always excluded for iPhone builds
384 #undef WEBRTC_CODEC_ISAC
385 #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT
386
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000387 #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000388
389#else // Non-iPhone
390
391// ----------------------------------------------------------------------------
392// Enumerators
393// ----------------------------------------------------------------------------
394
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000395// ----------------------------------------------------------------------------
396// Defines
397// ----------------------------------------------------------------------------
398
399 #define IPHONE_NOT_SUPPORTED(stat)
400#endif
401
402#else
403#define IPHONE_NOT_SUPPORTED(stat)
404#endif // #ifdef WEBRTC_MAC
405
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000406#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H