blob: 295f209834fc747f217f9c492e538c2a3916f244 [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"
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000020#include "webrtc/modules/audio_processing/include/audio_processing.h"
henrik.lundina9a6d4b2016-12-12 05:03:02 -080021#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23// ----------------------------------------------------------------------------
24// Enumerators
25// ----------------------------------------------------------------------------
26
andrew@webrtc.org4a6f62d2013-02-01 23:42:44 +000027namespace webrtc {
28
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000029// Internal buffer size required for mono audio, based on the highest sample
30// rate voice engine supports (10 ms of audio at 192 kHz).
Peter Kastingdce40cf2015-08-24 14:52:23 -070031static const size_t kMaxMonoDataSizeSamples = 1920;
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000032
niklase@google.com470e71d2011-07-07 08:21:25 +000033// VolumeControl
34enum { kMinVolumeLevel = 0 };
35enum { kMaxVolumeLevel = 255 };
36// Min scale factor for per-channel volume scaling
37const float kMinOutputVolumeScaling = 0.0f;
38// Max scale factor for per-channel volume scaling
39const float kMaxOutputVolumeScaling = 10.0f;
40// Min scale factor for output volume panning
41const float kMinOutputVolumePanning = 0.0f;
42// Max scale factor for output volume panning
43const float kMaxOutputVolumePanning = 1.0f;
44
45// DTMF
Jelena Marusic0d266052015-05-04 14:15:32 +020046enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
47enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
48enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
49enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
niklase@google.com470e71d2011-07-07 08:21:25 +000050enum { kMinTelephoneEventDuration = 100 };
Jelena Marusic0d266052015-05-04 14:15:32 +020051enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
52enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
53enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
54enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
55 // telephone events
56enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
niklase@google.com470e71d2011-07-07 08:21:25 +000057
58enum { kVoiceEngineMaxModuleVersionSize = 960 };
59
niklase@google.com470e71d2011-07-07 08:21:25 +000060// Audio processing
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000061const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
62const GainControl::Mode kDefaultAgcMode =
63#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +020064 GainControl::kAdaptiveDigital;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000065#else
Jelena Marusic0d266052015-05-04 14:15:32 +020066 GainControl::kAdaptiveAnalog;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000067#endif
68const bool kDefaultAgcState =
69#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +020070 false;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000071#else
Jelena Marusic0d266052015-05-04 14:15:32 +020072 true;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000073#endif
andrew@webrtc.org6c264cc2013-10-04 17:54:09 +000074const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
niklase@google.com470e71d2011-07-07 08:21:25 +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.org218c5422013-01-17 22:25:49 +0000106enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
niklase@google.com470e71d2011-07-07 08:21:25 +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.orgd900e8b2013-07-03 15:12:26 +0000124} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
niklase@google.com470e71d2011-07-07 08:21:25 +0000126// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000127// Macros
128// ----------------------------------------------------------------------------
129
Jelena Marusic0d266052015-05-04 14:15:32 +0200130#define NOT_SUPPORTED(stat) \
131 LOG_F(LS_ERROR) << "not supported"; \
132 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000133 return -1;
134
tfarinaa41ab932015-10-30 16:08:48 -0700135#if (!defined(NDEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
Jelena Marusic0d266052015-05-04 14:15:32 +0200136#include <windows.h>
137#include <stdio.h>
138#define DEBUG_PRINT(...) \
139 { \
140 char msg[256]; \
141 sprintf(msg, __VA_ARGS__); \
142 OutputDebugStringA(msg); \
niklase@google.com470e71d2011-07-07 08:21:25 +0000143 }
144#else
Jelena Marusic0d266052015-05-04 14:15:32 +0200145// special fix for visual 2003
146#define DEBUG_PRINT(exp) ((void)0)
tfarinaa41ab932015-10-30 16:08:48 -0700147#endif // !defined(NDEBUG) && defined(_WIN32)
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
Jelena Marusic0d266052015-05-04 14:15:32 +0200149#define CHECK_CHANNEL(channel) \
150 if (CheckChannel(channel) == -1) \
151 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
153// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000154// Inline functions
155// ----------------------------------------------------------------------------
156
Jelena Marusic0d266052015-05-04 14:15:32 +0200157namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
Jelena Marusic0d266052015-05-04 14:15:32 +0200159inline int VoEId(int veId, int chId) {
160 if (chId == -1) {
161 const int dummyChannel(99);
162 return (int)((veId << 16) + dummyChannel);
163 }
164 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000165}
166
Jelena Marusic0d266052015-05-04 14:15:32 +0200167inline int VoEModuleId(int veId, int chId) {
168 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
171// Convert module ID to internal VoE channel ID
Jelena Marusic0d266052015-05-04 14:15:32 +0200172inline int VoEChannelId(int moduleId) {
173 return (int)(moduleId & 0xffff);
niklase@google.com470e71d2011-07-07 08:21:25 +0000174}
175
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000176} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
178// ----------------------------------------------------------------------------
179// Platform settings
180// ----------------------------------------------------------------------------
181
182// *** WINDOWS ***
183
184#if defined(_WIN32)
185
Jelena Marusic0d266052015-05-04 14:15:32 +0200186#include <windows.h>
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000187
Jelena Marusic0d266052015-05-04 14:15:32 +0200188#pragma comment(lib, "winmm.lib")
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
Jelena Marusic0d266052015-05-04 14:15:32 +0200190#ifndef WEBRTC_EXTERNAL_TRANSPORT
191#pragma comment(lib, "ws2_32.lib")
192#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
194// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000195// Defines
196// ----------------------------------------------------------------------------
197
niklase@google.com470e71d2011-07-07 08:21:25 +0000198// Default device for Windows PC
Jelena Marusic0d266052015-05-04 14:15:32 +0200199#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
200 AudioDeviceModule::kDefaultCommunicationDevice
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
202#endif // #if (defined(_WIN32)
203
204// *** LINUX ***
205
206#ifdef WEBRTC_LINUX
207
niklase@google.com470e71d2011-07-07 08:21:25 +0000208#include <arpa/inet.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000209#include <netinet/in.h>
210#include <pthread.h>
211#include <sys/socket.h>
212#include <sys/types.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000213#ifndef QNX
Jelena Marusic0d266052015-05-04 14:15:32 +0200214#include <linux/net.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000215#ifndef ANDROID
Jelena Marusic0d266052015-05-04 14:15:32 +0200216#include <sys/soundcard.h>
217#endif // ANDROID
218#endif // QNX
niklase@google.com470e71d2011-07-07 08:21:25 +0000219#include <errno.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000220#include <fcntl.h>
221#include <sched.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000222#include <stdio.h>
223#include <stdlib.h>
224#include <string.h>
225#include <sys/ioctl.h>
226#include <sys/stat.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000227#include <sys/time.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000228#include <time.h>
229#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
231#define DWORD unsigned long int
232#define WINAPI
233#define LPVOID void *
234#define FALSE 0
235#define TRUE 1
236#define UINT unsigned int
237#define UCHAR unsigned char
238#define TCHAR char
239#ifdef QNX
240#define _stricmp stricmp
241#else
242#define _stricmp strcasecmp
243#endif
244#define GetLastError() errno
245#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200246#define LPCTSTR const char *
247#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000248#define wsprintf sprintf
249#define TEXT(a) a
250#define _ftprintf fprintf
251#define _tcslen strlen
252#define FAR
253#define __cdecl
254#define LPSOCKADDR struct sockaddr *
255
niklase@google.com470e71d2011-07-07 08:21:25 +0000256// Default device for Linux and Android
257#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
258
niklase@google.com470e71d2011-07-07 08:21:25 +0000259#endif // #ifdef WEBRTC_LINUX
260
261// *** WEBRTC_MAC ***
262// including iPhone
263
264#ifdef WEBRTC_MAC
265
niklase@google.com470e71d2011-07-07 08:21:25 +0000266#include <AudioUnit/AudioUnit.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000267#include <arpa/inet.h>
268#include <errno.h>
269#include <fcntl.h>
270#include <netinet/in.h>
271#include <pthread.h>
272#include <sched.h>
273#include <stdio.h>
274#include <stdlib.h>
275#include <string.h>
276#include <sys/socket.h>
277#include <sys/stat.h>
278#include <sys/time.h>
279#include <sys/types.h>
280#include <time.h>
281#include <unistd.h>
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000282#if !defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +0200283#include <CoreServices/CoreServices.h>
284#include <CoreAudio/CoreAudio.h>
285#include <AudioToolbox/DefaultAudioOutput.h>
286#include <AudioToolbox/AudioConverter.h>
287#include <CoreAudio/HostTime.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif
289
290#define DWORD unsigned long int
291#define WINAPI
292#define LPVOID void *
293#define FALSE 0
294#define TRUE 1
295#define SOCKADDR_IN struct sockaddr_in
296#define UINT unsigned int
297#define UCHAR unsigned char
298#define TCHAR char
299#define _stricmp strcasecmp
300#define GetLastError() errno
301#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200302#define LPCTSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000303#define wsprintf sprintf
304#define TEXT(a) a
305#define _ftprintf fprintf
306#define _tcslen strlen
307#define FAR
308#define __cdecl
309#define LPSOCKADDR struct sockaddr *
Jelena Marusic0d266052015-05-04 14:15:32 +0200310#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000311#define ULONG unsigned long
312
niklase@google.com470e71d2011-07-07 08:21:25 +0000313// Default device for Mac and iPhone
314#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif // #ifdef WEBRTC_MAC
316
Jelena Marusic0d266052015-05-04 14:15:32 +0200317#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H