blob: f78fb2c5589f0a2053eb028d79918676c34bb677 [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"
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
60// Base
61enum { kVoiceEngineVersionMaxMessageSize = 1024 };
62
niklase@google.com470e71d2011-07-07 08:21:25 +000063// Audio processing
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000064const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
65const GainControl::Mode kDefaultAgcMode =
66#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +020067 GainControl::kAdaptiveDigital;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000068#else
Jelena Marusic0d266052015-05-04 14:15:32 +020069 GainControl::kAdaptiveAnalog;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000070#endif
71const bool kDefaultAgcState =
72#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +020073 false;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000074#else
Jelena Marusic0d266052015-05-04 14:15:32 +020075 true;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000076#endif
andrew@webrtc.org6c264cc2013-10-04 17:54:09 +000077const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
79// Codec
80// Min init target rate for iSAC-wb
81enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
82// Max init target rate for iSAC-wb
83enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
84// Min init target rate for iSAC-swb
85enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
86// Max init target rate for iSAC-swb
87enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
88// Lowest max rate for iSAC-wb
89enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
90// Highest max rate for iSAC-wb
91enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
92// Lowest max rate for iSAC-swb
93enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
94// Highest max rate for iSAC-swb
95enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
96// Lowest max payload size for iSAC-wb
97enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
98// Highest max payload size for iSAC-wb
99enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
100// Lowest max payload size for iSAC-swb
101enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
102// Highest max payload size for iSAC-swb
103enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
104
105// VideoSync
106// Lowest minimum playout delay
107enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
108// Highest minimum playout delay
niklas.enbom@webrtc.org218c5422013-01-17 22:25:49 +0000109enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
111// Network
112// Min packet-timeout time for received RTP packets
113enum { kVoiceEngineMinPacketTimeoutSec = 1 };
114// Max packet-timeout time for received RTP packets
115enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
116// Min sample time for dead-or-alive detection
117enum { kVoiceEngineMinSampleTimeSec = 1 };
118// Max sample time for dead-or-alive detection
119enum { kVoiceEngineMaxSampleTimeSec = 150 };
120
121// RTP/RTCP
122// Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
123enum { kVoiceEngineMinRtpExtensionId = 1 };
124// Max 4-bit ID for RTP extension
125enum { kVoiceEngineMaxRtpExtensionId = 14 };
126
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000127} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
niklase@google.com470e71d2011-07-07 08:21:25 +0000129// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000130// Macros
131// ----------------------------------------------------------------------------
132
Jelena Marusic0d266052015-05-04 14:15:32 +0200133#define NOT_SUPPORTED(stat) \
134 LOG_F(LS_ERROR) << "not supported"; \
135 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
andrew@webrtc.org1e7ed7a2013-02-05 21:23:39 +0000136 return -1;
137
niklase@google.com470e71d2011-07-07 08:21:25 +0000138#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
Jelena Marusic0d266052015-05-04 14:15:32 +0200139#include <windows.h>
140#include <stdio.h>
141#define DEBUG_PRINT(...) \
142 { \
143 char msg[256]; \
144 sprintf(msg, __VA_ARGS__); \
145 OutputDebugStringA(msg); \
niklase@google.com470e71d2011-07-07 08:21:25 +0000146 }
147#else
Jelena Marusic0d266052015-05-04 14:15:32 +0200148// special fix for visual 2003
149#define DEBUG_PRINT(exp) ((void)0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000150#endif // defined(_DEBUG) && defined(_WIN32)
151
Jelena Marusic0d266052015-05-04 14:15:32 +0200152#define CHECK_CHANNEL(channel) \
153 if (CheckChannel(channel) == -1) \
154 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
156// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000157// Inline functions
158// ----------------------------------------------------------------------------
159
Jelena Marusic0d266052015-05-04 14:15:32 +0200160namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
Jelena Marusic0d266052015-05-04 14:15:32 +0200162inline int VoEId(int veId, int chId) {
163 if (chId == -1) {
164 const int dummyChannel(99);
165 return (int)((veId << 16) + dummyChannel);
166 }
167 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000168}
169
Jelena Marusic0d266052015-05-04 14:15:32 +0200170inline int VoEModuleId(int veId, int chId) {
171 return (int)((veId << 16) + chId);
niklase@google.com470e71d2011-07-07 08:21:25 +0000172}
173
174// Convert module ID to internal VoE channel ID
Jelena Marusic0d266052015-05-04 14:15:32 +0200175inline int VoEChannelId(int moduleId) {
176 return (int)(moduleId & 0xffff);
niklase@google.com470e71d2011-07-07 08:21:25 +0000177}
178
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000179} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
181// ----------------------------------------------------------------------------
182// Platform settings
183// ----------------------------------------------------------------------------
184
185// *** WINDOWS ***
186
187#if defined(_WIN32)
188
Jelena Marusic0d266052015-05-04 14:15:32 +0200189#include <windows.h>
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000190
Jelena Marusic0d266052015-05-04 14:15:32 +0200191#pragma comment(lib, "winmm.lib")
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
Jelena Marusic0d266052015-05-04 14:15:32 +0200193#ifndef WEBRTC_EXTERNAL_TRANSPORT
194#pragma comment(lib, "ws2_32.lib")
195#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
197// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000198// Defines
199// ----------------------------------------------------------------------------
200
niklase@google.com470e71d2011-07-07 08:21:25 +0000201// Default device for Windows PC
Jelena Marusic0d266052015-05-04 14:15:32 +0200202#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
203 AudioDeviceModule::kDefaultCommunicationDevice
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
205#endif // #if (defined(_WIN32)
206
207// *** LINUX ***
208
209#ifdef WEBRTC_LINUX
210
niklase@google.com470e71d2011-07-07 08:21:25 +0000211#include <arpa/inet.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000212#include <netinet/in.h>
213#include <pthread.h>
214#include <sys/socket.h>
215#include <sys/types.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000216#ifndef QNX
Jelena Marusic0d266052015-05-04 14:15:32 +0200217#include <linux/net.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000218#ifndef ANDROID
Jelena Marusic0d266052015-05-04 14:15:32 +0200219#include <sys/soundcard.h>
220#endif // ANDROID
221#endif // QNX
niklase@google.com470e71d2011-07-07 08:21:25 +0000222#include <errno.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#include <fcntl.h>
224#include <sched.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000225#include <stdio.h>
226#include <stdlib.h>
227#include <string.h>
228#include <sys/ioctl.h>
229#include <sys/stat.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000230#include <sys/time.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000231#include <time.h>
232#include <unistd.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000233
234#define DWORD unsigned long int
235#define WINAPI
236#define LPVOID void *
237#define FALSE 0
238#define TRUE 1
239#define UINT unsigned int
240#define UCHAR unsigned char
241#define TCHAR char
242#ifdef QNX
243#define _stricmp stricmp
244#else
245#define _stricmp strcasecmp
246#endif
247#define GetLastError() errno
248#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200249#define LPCTSTR const char *
250#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000251#define wsprintf sprintf
252#define TEXT(a) a
253#define _ftprintf fprintf
254#define _tcslen strlen
255#define FAR
256#define __cdecl
257#define LPSOCKADDR struct sockaddr *
258
niklase@google.com470e71d2011-07-07 08:21:25 +0000259// Default device for Linux and Android
260#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
261
niklase@google.com470e71d2011-07-07 08:21:25 +0000262#endif // #ifdef WEBRTC_LINUX
263
264// *** WEBRTC_MAC ***
265// including iPhone
266
267#ifdef WEBRTC_MAC
268
niklase@google.com470e71d2011-07-07 08:21:25 +0000269#include <AudioUnit/AudioUnit.h>
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +0000270#include <arpa/inet.h>
271#include <errno.h>
272#include <fcntl.h>
273#include <netinet/in.h>
274#include <pthread.h>
275#include <sched.h>
276#include <stdio.h>
277#include <stdlib.h>
278#include <string.h>
279#include <sys/socket.h>
280#include <sys/stat.h>
281#include <sys/time.h>
282#include <sys/types.h>
283#include <time.h>
284#include <unistd.h>
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000285#if !defined(WEBRTC_IOS)
Jelena Marusic0d266052015-05-04 14:15:32 +0200286#include <CoreServices/CoreServices.h>
287#include <CoreAudio/CoreAudio.h>
288#include <AudioToolbox/DefaultAudioOutput.h>
289#include <AudioToolbox/AudioConverter.h>
290#include <CoreAudio/HostTime.h>
niklase@google.com470e71d2011-07-07 08:21:25 +0000291#endif
292
293#define DWORD unsigned long int
294#define WINAPI
295#define LPVOID void *
296#define FALSE 0
297#define TRUE 1
298#define SOCKADDR_IN struct sockaddr_in
299#define UINT unsigned int
300#define UCHAR unsigned char
301#define TCHAR char
302#define _stricmp strcasecmp
303#define GetLastError() errno
304#define WSAGetLastError() errno
Jelena Marusic0d266052015-05-04 14:15:32 +0200305#define LPCTSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#define wsprintf sprintf
307#define TEXT(a) a
308#define _ftprintf fprintf
309#define _tcslen strlen
310#define FAR
311#define __cdecl
312#define LPSOCKADDR struct sockaddr *
Jelena Marusic0d266052015-05-04 14:15:32 +0200313#define LPCSTR const char *
niklase@google.com470e71d2011-07-07 08:21:25 +0000314#define ULONG unsigned long
315
niklase@google.com470e71d2011-07-07 08:21:25 +0000316// Default device for Mac and iPhone
317#define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
niklase@google.com470e71d2011-07-07 08:21:25 +0000318#endif // #ifdef WEBRTC_MAC
319
Jelena Marusic0d266052015-05-04 14:15:32 +0200320#endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H