blob: cde9470a78dcf92abca876c4c6721e37f7debbbc [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
andrew@webrtc.org40ee3d02014-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
niklase@google.com470e71d2011-07-07 08:21:25 +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
niklase@google.com470e71d2011-07-07 08:21:25 +000057enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
58
59enum { kVoiceEngineMaxModuleVersionSize = 960 };
60
61// Base
62enum { kVoiceEngineVersionMaxMessageSize = 1024 };
63
niklase@google.com470e71d2011-07-07 08:21:25 +000064// Audio processing
andrew@webrtc.orgf0a90c32013-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.org6c264cc2013-10-04 17:54:09 +000078const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
niklase@google.com470e71d2011-07-07 08:21:25 +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.org218c5422013-01-17 22:25:49 +0000110enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
niklase@google.com470e71d2011-07-07 08:21:25 +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.orgd900e8b2013-07-03 15:12:26 +0000128} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
niklase@google.com470e71d2011-07-07 08:21:25 +0000130// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000131// Macros
132// ----------------------------------------------------------------------------
133
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000134#define NOT_SUPPORTED(stat) \
135 LOG_F(LS_ERROR) << "not supported"; \
136 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
137 return -1;
138
niklase@google.com470e71d2011-07-07 08:21:25 +0000139#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
140 #include <windows.h>
141 #include <stdio.h>
142 #define DEBUG_PRINT(...) \
143 { \
144 char msg[256]; \
145 sprintf(msg, __VA_ARGS__); \
146 OutputDebugStringA(msg); \
147 }
148#else
149 // special fix for visual 2003
150 #define DEBUG_PRINT(exp) ((void)0)
151#endif // defined(_DEBUG) && defined(_WIN32)
152
153#define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
154
155// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000156// Inline functions
157// ----------------------------------------------------------------------------
158
159namespace webrtc
160{
161
pbos@webrtc.org92135212013-05-14 08:31:39 +0000162inline int VoEId(int veId, int chId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000163{
164 if (chId == -1)
165 {
166 const int dummyChannel(99);
167 return (int) ((veId << 16) + dummyChannel);
168 }
169 return (int) ((veId << 16) + chId);
170}
171
pbos@webrtc.org92135212013-05-14 08:31:39 +0000172inline int VoEModuleId(int veId, int chId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000173{
174 return (int) ((veId << 16) + chId);
175}
176
177// Convert module ID to internal VoE channel ID
pbos@webrtc.org92135212013-05-14 08:31:39 +0000178inline int VoEChannelId(int moduleId)
niklase@google.com470e71d2011-07-07 08:21:25 +0000179{
180 return (int) (moduleId & 0xffff);
181}
182
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000183} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
185// ----------------------------------------------------------------------------
186// Platform settings
187// ----------------------------------------------------------------------------
188
189// *** WINDOWS ***
190
191#if defined(_WIN32)
192
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000193 #include <windows.h>
194
niklase@google.com470e71d2011-07-07 08:21:25 +0000195 #pragma comment( lib, "winmm.lib" )
196
197 #ifndef WEBRTC_EXTERNAL_TRANSPORT
198 #pragma comment( lib, "ws2_32.lib" )
199 #endif
200
201// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000202// Defines
203// ----------------------------------------------------------------------------
204
niklase@google.com470e71d2011-07-07 08:21:25 +0000205// Default device for Windows PC
206 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
207 AudioDeviceModule::kDefaultCommunicationDevice
208
209#endif // #if (defined(_WIN32)
210
211// *** LINUX ***
212
213#ifdef WEBRTC_LINUX
214
niklase@google.com470e71d2011-07-07 08:21:25 +0000215#include <arpa/inet.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000216#include <netinet/in.h>
217#include <pthread.h>
218#include <sys/socket.h>
219#include <sys/types.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000220#ifndef QNX
221 #include <linux/net.h>
222#ifndef ANDROID
223 #include <sys/soundcard.h>
224#endif // ANDROID
225#endif // QNX
niklase@google.com470e71d2011-07-07 08:21:25 +0000226#include <errno.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000227#include <fcntl.h>
228#include <sched.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000229#include <stdio.h>
230#include <stdlib.h>
231#include <string.h>
232#include <sys/ioctl.h>
233#include <sys/stat.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000234#include <sys/time.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000235#include <time.h>
236#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000237
238#define DWORD unsigned long int
239#define WINAPI
240#define LPVOID void *
241#define FALSE 0
242#define TRUE 1
243#define UINT unsigned int
244#define UCHAR unsigned char
245#define TCHAR char
246#ifdef QNX
247#define _stricmp stricmp
248#else
249#define _stricmp strcasecmp
250#endif
251#define GetLastError() errno
252#define WSAGetLastError() errno
253#define LPCTSTR const char*
254#define LPCSTR const char*
255#define wsprintf sprintf
256#define TEXT(a) a
257#define _ftprintf fprintf
258#define _tcslen strlen
259#define FAR
260#define __cdecl
261#define LPSOCKADDR struct sockaddr *
262
niklase@google.com470e71d2011-07-07 08:21:25 +0000263// Default device for Linux and Android
264#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
265
niklase@google.com470e71d2011-07-07 08:21:25 +0000266#endif // #ifdef WEBRTC_LINUX
267
268// *** WEBRTC_MAC ***
269// including iPhone
270
271#ifdef WEBRTC_MAC
272
niklase@google.com470e71d2011-07-07 08:21:25 +0000273#include <AudioUnit/AudioUnit.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000274#include <arpa/inet.h>
275#include <errno.h>
276#include <fcntl.h>
277#include <netinet/in.h>
278#include <pthread.h>
279#include <sched.h>
280#include <stdio.h>
281#include <stdlib.h>
282#include <string.h>
283#include <sys/socket.h>
284#include <sys/stat.h>
285#include <sys/time.h>
286#include <sys/types.h>
287#include <time.h>
288#include <unistd.h>
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000289#if !defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 #include <CoreServices/CoreServices.h>
291 #include <CoreAudio/CoreAudio.h>
292 #include <AudioToolbox/DefaultAudioOutput.h>
293 #include <AudioToolbox/AudioConverter.h>
294 #include <CoreAudio/HostTime.h>
295#endif
296
297#define DWORD unsigned long int
298#define WINAPI
299#define LPVOID void *
300#define FALSE 0
301#define TRUE 1
302#define SOCKADDR_IN struct sockaddr_in
303#define UINT unsigned int
304#define UCHAR unsigned char
305#define TCHAR char
306#define _stricmp strcasecmp
307#define GetLastError() errno
308#define WSAGetLastError() errno
309#define LPCTSTR const char*
310#define wsprintf sprintf
311#define TEXT(a) a
312#define _ftprintf fprintf
313#define _tcslen strlen
314#define FAR
315#define __cdecl
316#define LPSOCKADDR struct sockaddr *
317#define LPCSTR const char*
318#define ULONG unsigned long
319
niklase@google.com470e71d2011-07-07 08:21:25 +0000320// Default device for Mac and iPhone
321#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
niklase@google.com470e71d2011-07-07 08:21:25 +0000322#endif // #ifdef WEBRTC_MAC
323
niklase@google.com470e71d2011-07-07 08:21:25 +0000324#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H