2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
12 * This file contains common constants for VoiceEngine, as well as
13 * platform specific settings and include files.
16 #ifndef WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
17 #define WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
19 #include "webrtc/common_types.h"
20 #include "webrtc/engine_configurations.h"
21 #include "webrtc/modules/audio_processing/include/audio_processing.h"
22 #include "webrtc/system_wrappers/interface/logging.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
30 // Internal buffer size required for mono audio, based on the highest sample
31 // rate voice engine supports (10 ms of audio at 192 kHz).
32 static const int kMaxMonoDataSizeSamples = 1920;
35 enum { kMinVolumeLevel = 0 };
36 enum { kMaxVolumeLevel = 255 };
37 // Min scale factor for per-channel volume scaling
38 const float kMinOutputVolumeScaling = 0.0f;
39 // Max scale factor for per-channel volume scaling
40 const float kMaxOutputVolumeScaling = 10.0f;
41 // Min scale factor for output volume panning
42 const float kMinOutputVolumePanning = 0.0f;
43 // Max scale factor for output volume panning
44 const float kMaxOutputVolumePanning = 1.0f;
47 enum { kMinDtmfEventCode = 0 }; // DTMF digit "0"
48 enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D"
49 enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1)
50 enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1)
51 enum { kMinTelephoneEventDuration = 100 };
52 enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16
53 enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0
54 enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0
55 enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two
57 enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet
59 enum { kVoiceEngineMaxModuleVersionSize = 960 };
62 enum { kVoiceEngineVersionMaxMessageSize = 1024 };
65 const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate;
66 const GainControl::Mode kDefaultAgcMode =
67 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
68 GainControl::kAdaptiveDigital;
70 GainControl::kAdaptiveAnalog;
72 const bool kDefaultAgcState =
73 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
78 const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
81 // Min init target rate for iSAC-wb
82 enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 };
83 // Max init target rate for iSAC-wb
84 enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 };
85 // Min init target rate for iSAC-swb
86 enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 };
87 // Max init target rate for iSAC-swb
88 enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 };
89 // Lowest max rate for iSAC-wb
90 enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 };
91 // Highest max rate for iSAC-wb
92 enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 };
93 // Lowest max rate for iSAC-swb
94 enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 };
95 // Highest max rate for iSAC-swb
96 enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 };
97 // Lowest max payload size for iSAC-wb
98 enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 };
99 // Highest max payload size for iSAC-wb
100 enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 };
101 // Lowest max payload size for iSAC-swb
102 enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 };
103 // Highest max payload size for iSAC-swb
104 enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 };
107 // Lowest minimum playout delay
108 enum { kVoiceEngineMinMinPlayoutDelayMs = 0 };
109 // Highest minimum playout delay
110 enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
113 // Min packet-timeout time for received RTP packets
114 enum { kVoiceEngineMinPacketTimeoutSec = 1 };
115 // Max packet-timeout time for received RTP packets
116 enum { kVoiceEngineMaxPacketTimeoutSec = 150 };
117 // Min sample time for dead-or-alive detection
118 enum { kVoiceEngineMinSampleTimeSec = 1 };
119 // Max sample time for dead-or-alive detection
120 enum { kVoiceEngineMaxSampleTimeSec = 150 };
123 // Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285)
124 enum { kVoiceEngineMinRtpExtensionId = 1 };
125 // Max 4-bit ID for RTP extension
126 enum { kVoiceEngineMaxRtpExtensionId = 14 };
128 } // namespace webrtc
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 #define NOT_SUPPORTED(stat) \
135 LOG_F(LS_ERROR) << "not supported"; \
136 stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \
139 #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
142 #define DEBUG_PRINT(...) \
145 sprintf(msg, __VA_ARGS__); \
146 OutputDebugStringA(msg); \
149 // special fix for visual 2003
150 #define DEBUG_PRINT(exp) ((void)0)
151 #endif // defined(_DEBUG) && defined(_WIN32)
153 #define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1;
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
162 inline int VoEId(int veId, int chId)
166 const int dummyChannel(99);
167 return (int) ((veId << 16) + dummyChannel);
169 return (int) ((veId << 16) + chId);
172 inline int VoEModuleId(int veId, int chId)
174 return (int) ((veId << 16) + chId);
177 // Convert module ID to internal VoE channel ID
178 inline int VoEChannelId(int moduleId)
180 return (int) (moduleId & 0xffff);
183 } // namespace webrtc
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
195 #pragma comment( lib, "winmm.lib" )
197 #ifndef WEBRTC_EXTERNAL_TRANSPORT
198 #pragma comment( lib, "ws2_32.lib" )
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 // Default device for Windows PC
206 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
207 AudioDeviceModule::kDefaultCommunicationDevice
209 #endif // #if (defined(_WIN32)
215 #include <arpa/inet.h>
216 #include <netinet/in.h>
218 #include <sys/socket.h>
219 #include <sys/types.h>
221 #include <linux/net.h>
223 #include <sys/soundcard.h>
232 #include <sys/ioctl.h>
233 #include <sys/stat.h>
234 #include <sys/time.h>
238 #define DWORD unsigned long int
240 #define LPVOID void *
243 #define UINT unsigned int
244 #define UCHAR unsigned char
247 #define _stricmp stricmp
249 #define _stricmp strcasecmp
251 #define GetLastError() errno
252 #define WSAGetLastError() errno
253 #define LPCTSTR const char*
254 #define LPCSTR const char*
255 #define wsprintf sprintf
257 #define _ftprintf fprintf
258 #define _tcslen strlen
261 #define LPSOCKADDR struct sockaddr *
263 // Default device for Linux and Android
264 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
266 #endif // #ifdef WEBRTC_LINUX
268 // *** WEBRTC_MAC ***
273 #include <AudioUnit/AudioUnit.h>
274 #include <arpa/inet.h>
277 #include <netinet/in.h>
283 #include <sys/socket.h>
284 #include <sys/stat.h>
285 #include <sys/time.h>
286 #include <sys/types.h>
289 #if !defined(WEBRTC_IOS)
290 #include <CoreServices/CoreServices.h>
291 #include <CoreAudio/CoreAudio.h>
292 #include <AudioToolbox/DefaultAudioOutput.h>
293 #include <AudioToolbox/AudioConverter.h>
294 #include <CoreAudio/HostTime.h>
297 #define DWORD unsigned long int
299 #define LPVOID void *
302 #define SOCKADDR_IN struct sockaddr_in
303 #define UINT unsigned int
304 #define UCHAR unsigned char
306 #define _stricmp strcasecmp
307 #define GetLastError() errno
308 #define WSAGetLastError() errno
309 #define LPCTSTR const char*
310 #define wsprintf sprintf
312 #define _ftprintf fprintf
313 #define _tcslen strlen
316 #define LPSOCKADDR struct sockaddr *
317 #define LPCSTR const char*
318 #define ULONG unsigned long
320 // Default device for Mac and iPhone
321 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
322 #endif // #ifdef WEBRTC_MAC
324 #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H