blob: 5fd8120ec3840b757901777e868f33c2c1408101 [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
Jelena Marusic0d266052015-05-04 14:15:32 +020047enum { 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)
niklase@google.com470e71d2011-07-07 08:21:25 +000051enum { kMinTelephoneEventDuration = 100 };
Jelena Marusic0d266052015-05-04 14:15:32 +020052enum { 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
niklase@google.com470e71d2011-07-07 08:21:25 +000058
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)
Jelena Marusic0d266052015-05-04 14:15:32 +020068 GainControl::kAdaptiveDigital;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000069#else
Jelena Marusic0d266052015-05-04 14:15:32 +020070 GainControl::kAdaptiveAnalog;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000071#endif
72const bool kDefaultAgcState =
73#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +020074 false;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000075#else
Jelena Marusic0d266052015-05-04 14:15:32 +020076 true;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000077#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
Jelena Marusic0d266052015-05-04 14:15:32 +0200134#define NOT_SUPPORTED(stat) \
135 LOG_F(LS_ERROR) << "not supported"; \
136 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000137 return -1;
138
niklase@google.com470e71d2011-07-07 08:21:25 +0000139#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
Jelena Marusic0d266052015-05-04 14:15:32 +0200140#include <windows.h>
141#include <stdio.h>
142#define DEBUG_PRINT(...) \
143 { \
144 char msg[256]; \
145 sprintf(msg, __VA_ARGS__); \
146 OutputDebugStringA(msg); \
niklase@google.com470e71d2011-07-07 08:21:25 +0000147 }
148#else
Jelena Marusic0d266052015-05-04 14:15:32 +0200149// special fix for visual 2003
150#define DEBUG_PRINT(exp) ((void)0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000151#endif // defined(_DEBUG) && defined(_WIN32)
152
Jelena Marusic0d266052015-05-04 14:15:32 +0200153#define CHECK_CHANNEL(channel) \
154 if (CheckChannel(channel) == -1) \
155 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
157// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000158// Inline functions
159// ----------------------------------------------------------------------------
160
Jelena Marusic0d266052015-05-04 14:15:32 +0200161namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
Jelena Marusic0d266052015-05-04 14:15:32 +0200163inline int VoEId(int veId, int chId) {
164 if (chId == -1) {
165 const int dummyChannel(99);
166 return (int)((veId << 16) + dummyChannel);
167 }
168 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
Jelena Marusic0d266052015-05-04 14:15:32 +0200171inline int VoEModuleId(int veId, int chId) {
172 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000173}
174
175// Convert module ID to internal VoE channel ID
Jelena Marusic0d266052015-05-04 14:15:32 +0200176inline int VoEChannelId(int moduleId) {
177 return (int)(moduleId & 0xffff);
niklase@google.com470e71d2011-07-07 08:21:25 +0000178}
179
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000180} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
182// ----------------------------------------------------------------------------
183// Platform settings
184// ----------------------------------------------------------------------------
185
186// *** WINDOWS ***
187
188#if defined(_WIN32)
189
Jelena Marusic0d266052015-05-04 14:15:32 +0200190#include <windows.h>
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000191
Jelena Marusic0d266052015-05-04 14:15:32 +0200192#pragma comment(lib, "winmm.lib")
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
Jelena Marusic0d266052015-05-04 14:15:32 +0200194#ifndef WEBRTC_EXTERNAL_TRANSPORT
195#pragma comment(lib, "ws2_32.lib")
196#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
198// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000199// Defines
200// ----------------------------------------------------------------------------
201
niklase@google.com470e71d2011-07-07 08:21:25 +0000202// Default device for Windows PC
Jelena Marusic0d266052015-05-04 14:15:32 +0200203#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
204 AudioDeviceModule::kDefaultCommunicationDevice
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
206#endif // #if (defined(_WIN32)
207
208// *** LINUX ***
209
210#ifdef WEBRTC_LINUX
211
niklase@google.com470e71d2011-07-07 08:21:25 +0000212#include <arpa/inet.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000213#include <netinet/in.h>
214#include <pthread.h>
215#include <sys/socket.h>
216#include <sys/types.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000217#ifndef QNX
Jelena Marusic0d266052015-05-04 14:15:32 +0200218#include <linux/net.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000219#ifndef ANDROID
Jelena Marusic0d266052015-05-04 14:15:32 +0200220#include <sys/soundcard.h>
221#endif // ANDROID
222#endif // QNX
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#include <errno.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000224#include <fcntl.h>
225#include <sched.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000226#include <stdio.h>
227#include <stdlib.h>
228#include <string.h>
229#include <sys/ioctl.h>
230#include <sys/stat.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000231#include <sys/time.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000232#include <time.h>
233#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
235#define DWORD unsigned long int
236#define WINAPI
237#define LPVOID void *
238#define FALSE 0
239#define TRUE 1
240#define UINT unsigned int
241#define UCHAR unsigned char
242#define TCHAR char
243#ifdef QNX
244#define _stricmp stricmp
245#else
246#define _stricmp strcasecmp
247#endif
248#define GetLastError() errno
249#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200250#define LPCTSTR const char *
251#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000252#define wsprintf sprintf
253#define TEXT(a) a
254#define _ftprintf fprintf
255#define _tcslen strlen
256#define FAR
257#define __cdecl
258#define LPSOCKADDR struct sockaddr *
259
niklase@google.com470e71d2011-07-07 08:21:25 +0000260// Default device for Linux and Android
261#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
262
niklase@google.com470e71d2011-07-07 08:21:25 +0000263#endif // #ifdef WEBRTC_LINUX
264
265// *** WEBRTC_MAC ***
266// including iPhone
267
268#ifdef WEBRTC_MAC
269
niklase@google.com470e71d2011-07-07 08:21:25 +0000270#include <AudioUnit/AudioUnit.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000271#include <arpa/inet.h>
272#include <errno.h>
273#include <fcntl.h>
274#include <netinet/in.h>
275#include <pthread.h>
276#include <sched.h>
277#include <stdio.h>
278#include <stdlib.h>
279#include <string.h>
280#include <sys/socket.h>
281#include <sys/stat.h>
282#include <sys/time.h>
283#include <sys/types.h>
284#include <time.h>
285#include <unistd.h>
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000286#if !defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +0200287#include <CoreServices/CoreServices.h>
288#include <CoreAudio/CoreAudio.h>
289#include <AudioToolbox/DefaultAudioOutput.h>
290#include <AudioToolbox/AudioConverter.h>
291#include <CoreAudio/HostTime.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000292#endif
293
294#define DWORD unsigned long int
295#define WINAPI
296#define LPVOID void *
297#define FALSE 0
298#define TRUE 1
299#define SOCKADDR_IN struct sockaddr_in
300#define UINT unsigned int
301#define UCHAR unsigned char
302#define TCHAR char
303#define _stricmp strcasecmp
304#define GetLastError() errno
305#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200306#define LPCTSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000307#define wsprintf sprintf
308#define TEXT(a) a
309#define _ftprintf fprintf
310#define _tcslen strlen
311#define FAR
312#define __cdecl
313#define LPSOCKADDR struct sockaddr *
Jelena Marusic0d266052015-05-04 14:15:32 +0200314#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#define ULONG unsigned long
316
niklase@google.com470e71d2011-07-07 08:21:25 +0000317// Default device for Mac and iPhone
318#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
niklase@google.com470e71d2011-07-07 08:21:25 +0000319#endif // #ifdef WEBRTC_MAC
320
Jelena Marusic0d266052015-05-04 14:15:32 +0200321#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H