blob: b3cba7c33076b1905b6fd169d16aeab4e3d69384 [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.orgbf4f2322014-04-03 21:56:01 +000030// Internal buffer size required for mono audio, based on the highest sample
31// rate voice engine supports (10 ms of audio at 192 kHz).
32static const int kMaxMonoDataSizeSamples = 1920;
33
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000034// VolumeControl
35enum { kMinVolumeLevel = 0 };
36enum { kMaxVolumeLevel = 255 };
37// Min scale factor for per-channel volume scaling
38const float kMinOutputVolumeScaling = 0.0f;
39// Max scale factor for per-channel volume scaling
40const float kMaxOutputVolumeScaling = 10.0f;
41// Min scale factor for output volume panning
42const float kMinOutputVolumePanning = 0.0f;
43// Max scale factor for output volume panning
44const float kMaxOutputVolumePanning = 1.0f;
45
46// DTMF
47enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
48enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
49enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
50enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
51enum { kMinTelephoneEventDuration = 100 };
52enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
53enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
54enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
55enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
56 // telephone events
57enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
58
59enum { kVoiceEngineMaxModuleVersionSize = 960 };
60
61// Base
62enum { kVoiceEngineVersionMaxMessageSize = 1024 };
63
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000064// Audio processing
andrew@webrtc.org6316d172013-03-05 01:12:49 +000065const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
66const GainControl::Mode kDefaultAgcMode =
67#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
68 GainControl::kAdaptiveDigital;
69#else
70 GainControl::kAdaptiveAnalog;
71#endif
72const bool kDefaultAgcState =
73#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
74 false;
75#else
76 true;
77#endif
andrew@webrtc.org28ea6f82013-10-04 17:54:09 +000078const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000079
80// Codec
81// Min init target rate for iSAC-wb
82enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
83// Max init target rate for iSAC-wb
84enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
85// Min init target rate for iSAC-swb
86enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
87// Max init target rate for iSAC-swb
88enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
89// Lowest max rate for iSAC-wb
90enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
91// Highest max rate for iSAC-wb
92enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
93// Lowest max rate for iSAC-swb
94enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
95// Highest max rate for iSAC-swb
96enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
97// Lowest max payload size for iSAC-wb
98enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
99// Highest max payload size for iSAC-wb
100enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
101// Lowest max payload size for iSAC-swb
102enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
103// Highest max payload size for iSAC-swb
104enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
105
106// VideoSync
107// Lowest minimum playout delay
108enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
109// Highest minimum playout delay
niklas.enbom@webrtc.org99e89cd2013-01-17 22:25:49 +0000110enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000111
112// Network
113// Min packet-timeout time for received RTP packets
114enum { kVoiceEngineMinPacketTimeoutSec = 1 };
115// Max packet-timeout time for received RTP packets
116enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
117// Min sample time for dead-or-alive detection
118enum { kVoiceEngineMinSampleTimeSec = 1 };
119// Max sample time for dead-or-alive detection
120enum { kVoiceEngineMaxSampleTimeSec = 150 };
121
122// RTP/RTCP
123// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
124enum { kVoiceEngineMinRtpExtensionId = 1 };
125// Max 4-bit ID for RTP extension
126enum { kVoiceEngineMaxRtpExtensionId = 14 };
127
pbos@webrtc.org5ab7b932013-07-03 15:12:26 +0000128} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000129
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000130// ----------------------------------------------------------------------------
131// Build information macros
132// ----------------------------------------------------------------------------
133
134#if defined(_DEBUG)
135#define BUILDMODE "d"
136#elif defined(DEBUG)
137#define BUILDMODE "d"
138#elif defined(NDEBUG)
139#define BUILDMODE "r"
140#else
141#define BUILDMODE "?"
142#endif
143
144#define BUILDTIME __TIME__
145#define BUILDDATE __DATE__
146
147// Example: "Oct 10 2002 12:05:30 r"
148#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE
149
150// ----------------------------------------------------------------------------
151// Macros
152// ----------------------------------------------------------------------------
153
andrew@webrtc.org4484b832013-02-05 21:23:39 +0000154#define NOT_SUPPORTED(stat) \
155 LOG_F(LS_ERROR) << "not supported"; \
156 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
157 return -1;
158
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000159#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
160 #include <windows.h>
161 #include <stdio.h>
162 #define DEBUG_PRINT(...) \
163 { \
164 char msg[256]; \
165 sprintf(msg, __VA_ARGS__); \
166 OutputDebugStringA(msg); \
167 }
168#else
169 // special fix for visual 2003
170 #define DEBUG_PRINT(exp) ((void)0)
171#endif // defined(_DEBUG) && defined(_WIN32)
172
173#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
174
175// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000176// Inline functions
177// ----------------------------------------------------------------------------
178
179namespace webrtc
180{
181
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000182inline int VoEId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000183{
184 if (chId == -1)
185 {
186 const int dummyChannel(99);
187 return (int) ((veId << 16) + dummyChannel);
188 }
189 return (int) ((veId << 16) + chId);
190}
191
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000192inline int VoEModuleId(int veId, int chId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000193{
194 return (int) ((veId << 16) + chId);
195}
196
197// Convert module ID to internal VoE channel ID
pbos@webrtc.org07a1c112013-05-14 08:31:39 +0000198inline int VoEChannelId(int moduleId)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000199{
200 return (int) (moduleId & 0xffff);
201}
202
pbos@webrtc.org5ab7b932013-07-03 15:12:26 +0000203} // namespace webrtc
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000204
205// ----------------------------------------------------------------------------
206// Platform settings
207// ----------------------------------------------------------------------------
208
209// *** WINDOWS ***
210
211#if defined(_WIN32)
212
andrew@webrtc.org81c4d242013-09-09 17:50:10 +0000213 #include <windows.h>
214
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000215 #pragma comment( lib, "winmm.lib" )
216
217 #ifndef WEBRTC_EXTERNAL_TRANSPORT
218 #pragma comment( lib, "ws2_32.lib" )
219 #endif
220
221// ----------------------------------------------------------------------------
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000222// Defines
223// ----------------------------------------------------------------------------
224
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000225// Default device for Windows PC
226 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
227 AudioDeviceModule::kDefaultCommunicationDevice
228
229#endif // #if (defined(_WIN32)
230
231// *** LINUX ***
232
233#ifdef WEBRTC_LINUX
234
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000235#include <arpa/inet.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000236#include <netinet/in.h>
237#include <pthread.h>
238#include <sys/socket.h>
239#include <sys/types.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000240#ifndef QNX
241 #include <linux/net.h>
242#ifndef ANDROID
243 #include <sys/soundcard.h>
244#endif // ANDROID
245#endif // QNX
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000246#include <errno.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000247#include <fcntl.h>
248#include <sched.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000249#include <stdio.h>
250#include <stdlib.h>
251#include <string.h>
252#include <sys/ioctl.h>
253#include <sys/stat.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000254#include <sys/time.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000255#include <time.h>
256#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000257
258#define DWORD unsigned long int
259#define WINAPI
260#define LPVOID void *
261#define FALSE 0
262#define TRUE 1
263#define UINT unsigned int
264#define UCHAR unsigned char
265#define TCHAR char
266#ifdef QNX
267#define _stricmp stricmp
268#else
269#define _stricmp strcasecmp
270#endif
271#define GetLastError() errno
272#define WSAGetLastError() errno
273#define LPCTSTR const char*
274#define LPCSTR const char*
275#define wsprintf sprintf
276#define TEXT(a) a
277#define _ftprintf fprintf
278#define _tcslen strlen
279#define FAR
280#define __cdecl
281#define LPSOCKADDR struct sockaddr *
282
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000283// Default device for Linux and Android
284#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
285
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000286#endif // #ifdef WEBRTC_LINUX
287
288// *** WEBRTC_MAC ***
289// including iPhone
290
291#ifdef WEBRTC_MAC
292
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000293#include <AudioUnit/AudioUnit.h>
pbos@webrtc.orgbe72fe42013-05-21 13:52:32 +0000294#include <arpa/inet.h>
295#include <errno.h>
296#include <fcntl.h>
297#include <netinet/in.h>
298#include <pthread.h>
299#include <sched.h>
300#include <stdio.h>
301#include <stdlib.h>
302#include <string.h>
303#include <sys/socket.h>
304#include <sys/stat.h>
305#include <sys/time.h>
306#include <sys/types.h>
307#include <time.h>
308#include <unistd.h>
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000309#if !defined(WEBRTC_IOS)
310 #include <CoreServices/CoreServices.h>
311 #include <CoreAudio/CoreAudio.h>
312 #include <AudioToolbox/DefaultAudioOutput.h>
313 #include <AudioToolbox/AudioConverter.h>
314 #include <CoreAudio/HostTime.h>
315#endif
316
317#define DWORD unsigned long int
318#define WINAPI
319#define LPVOID void *
320#define FALSE 0
321#define TRUE 1
322#define SOCKADDR_IN struct sockaddr_in
323#define UINT unsigned int
324#define UCHAR unsigned char
325#define TCHAR char
326#define _stricmp strcasecmp
327#define GetLastError() errno
328#define WSAGetLastError() errno
329#define LPCTSTR const char*
330#define wsprintf sprintf
331#define TEXT(a) a
332#define _ftprintf fprintf
333#define _tcslen strlen
334#define FAR
335#define __cdecl
336#define LPSOCKADDR struct sockaddr *
337#define LPCSTR const char*
338#define ULONG unsigned long
339
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000340// Default device for Mac and iPhone
341#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000342#endif // #ifdef WEBRTC_MAC
343
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000344#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H