andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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.org | 4484b83 | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 19 | #include "webrtc/common_types.h" |
| 20 | #include "webrtc/engine_configurations.h" |
andrew@webrtc.org | 6316d17 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
andrew@webrtc.org | 4484b83 | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 22 | #include "webrtc/system_wrappers/interface/logging.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | // Enumerators |
| 26 | // ---------------------------------------------------------------------------- |
| 27 | |
andrew@webrtc.org | 48bfaa8 | 2013-02-01 23:42:44 +0000 | [diff] [blame] | 28 | namespace webrtc { |
| 29 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | // VolumeControl |
| 31 | enum { kMinVolumeLevel = 0 }; |
| 32 | enum { kMaxVolumeLevel = 255 }; |
| 33 | // Min scale factor for per-channel volume scaling |
| 34 | const float kMinOutputVolumeScaling = 0.0f; |
| 35 | // Max scale factor for per-channel volume scaling |
| 36 | const float kMaxOutputVolumeScaling = 10.0f; |
| 37 | // Min scale factor for output volume panning |
| 38 | const float kMinOutputVolumePanning = 0.0f; |
| 39 | // Max scale factor for output volume panning |
| 40 | const float kMaxOutputVolumePanning = 1.0f; |
| 41 | |
| 42 | // DTMF |
| 43 | enum { kMinDtmfEventCode = 0 }; // DTMF digit "0" |
| 44 | enum { kMaxDtmfEventCode = 15 }; // DTMF digit "D" |
| 45 | enum { kMinTelephoneEventCode = 0 }; // RFC4733 (Section 2.3.1) |
| 46 | enum { kMaxTelephoneEventCode = 255 }; // RFC4733 (Section 2.3.1) |
| 47 | enum { kMinTelephoneEventDuration = 100 }; |
| 48 | enum { kMaxTelephoneEventDuration = 60000 }; // Actual limit is 2^16 |
| 49 | enum { kMinTelephoneEventAttenuation = 0 }; // 0 dBm0 |
| 50 | enum { kMaxTelephoneEventAttenuation = 36 }; // -36 dBm0 |
| 51 | enum { kMinTelephoneEventSeparationMs = 100 }; // Min delta time between two |
| 52 | // telephone events |
| 53 | enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet |
| 54 | |
| 55 | enum { kVoiceEngineMaxModuleVersionSize = 960 }; |
| 56 | |
| 57 | // Base |
| 58 | enum { kVoiceEngineVersionMaxMessageSize = 1024 }; |
| 59 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 60 | // Audio processing |
andrew@webrtc.org | 6316d17 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 61 | const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate; |
| 62 | const GainControl::Mode kDefaultAgcMode = |
| 63 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 64 | GainControl::kAdaptiveDigital; |
| 65 | #else |
| 66 | GainControl::kAdaptiveAnalog; |
| 67 | #endif |
| 68 | const bool kDefaultAgcState = |
| 69 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 70 | false; |
| 71 | #else |
| 72 | true; |
| 73 | #endif |
andrew@webrtc.org | 28ea6f8 | 2013-10-04 17:54:09 +0000 | [diff] [blame^] | 74 | const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 75 | |
| 76 | // Codec |
| 77 | // Min init target rate for iSAC-wb |
| 78 | enum { kVoiceEngineMinIsacInitTargetRateBpsWb = 10000 }; |
| 79 | // Max init target rate for iSAC-wb |
| 80 | enum { kVoiceEngineMaxIsacInitTargetRateBpsWb = 32000 }; |
| 81 | // Min init target rate for iSAC-swb |
| 82 | enum { kVoiceEngineMinIsacInitTargetRateBpsSwb = 10000 }; |
| 83 | // Max init target rate for iSAC-swb |
| 84 | enum { kVoiceEngineMaxIsacInitTargetRateBpsSwb = 56000 }; |
| 85 | // Lowest max rate for iSAC-wb |
| 86 | enum { kVoiceEngineMinIsacMaxRateBpsWb = 32000 }; |
| 87 | // Highest max rate for iSAC-wb |
| 88 | enum { kVoiceEngineMaxIsacMaxRateBpsWb = 53400 }; |
| 89 | // Lowest max rate for iSAC-swb |
| 90 | enum { kVoiceEngineMinIsacMaxRateBpsSwb = 32000 }; |
| 91 | // Highest max rate for iSAC-swb |
| 92 | enum { kVoiceEngineMaxIsacMaxRateBpsSwb = 107000 }; |
| 93 | // Lowest max payload size for iSAC-wb |
| 94 | enum { kVoiceEngineMinIsacMaxPayloadSizeBytesWb = 120 }; |
| 95 | // Highest max payload size for iSAC-wb |
| 96 | enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesWb = 400 }; |
| 97 | // Lowest max payload size for iSAC-swb |
| 98 | enum { kVoiceEngineMinIsacMaxPayloadSizeBytesSwb = 120 }; |
| 99 | // Highest max payload size for iSAC-swb |
| 100 | enum { kVoiceEngineMaxIsacMaxPayloadSizeBytesSwb = 600 }; |
| 101 | |
| 102 | // VideoSync |
| 103 | // Lowest minimum playout delay |
| 104 | enum { kVoiceEngineMinMinPlayoutDelayMs = 0 }; |
| 105 | // Highest minimum playout delay |
niklas.enbom@webrtc.org | 99e89cd | 2013-01-17 22:25:49 +0000 | [diff] [blame] | 106 | enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 }; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 107 | |
| 108 | // Network |
| 109 | // Min packet-timeout time for received RTP packets |
| 110 | enum { kVoiceEngineMinPacketTimeoutSec = 1 }; |
| 111 | // Max packet-timeout time for received RTP packets |
| 112 | enum { kVoiceEngineMaxPacketTimeoutSec = 150 }; |
| 113 | // Min sample time for dead-or-alive detection |
| 114 | enum { kVoiceEngineMinSampleTimeSec = 1 }; |
| 115 | // Max sample time for dead-or-alive detection |
| 116 | enum { kVoiceEngineMaxSampleTimeSec = 150 }; |
| 117 | |
| 118 | // RTP/RTCP |
| 119 | // Min 4-bit ID for RTP extension (see section 4.2 in RFC 5285) |
| 120 | enum { kVoiceEngineMinRtpExtensionId = 1 }; |
| 121 | // Max 4-bit ID for RTP extension |
| 122 | enum { kVoiceEngineMaxRtpExtensionId = 14 }; |
| 123 | |
pbos@webrtc.org | 5ab7b93 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 124 | } // namespace webrtc |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 125 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 126 | // ---------------------------------------------------------------------------- |
| 127 | // Build information macros |
| 128 | // ---------------------------------------------------------------------------- |
| 129 | |
| 130 | #if defined(_DEBUG) |
| 131 | #define BUILDMODE "d" |
| 132 | #elif defined(DEBUG) |
| 133 | #define BUILDMODE "d" |
| 134 | #elif defined(NDEBUG) |
| 135 | #define BUILDMODE "r" |
| 136 | #else |
| 137 | #define BUILDMODE "?" |
| 138 | #endif |
| 139 | |
| 140 | #define BUILDTIME __TIME__ |
| 141 | #define BUILDDATE __DATE__ |
| 142 | |
| 143 | // Example: "Oct 10 2002 12:05:30 r" |
| 144 | #define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE |
| 145 | |
| 146 | // ---------------------------------------------------------------------------- |
| 147 | // Macros |
| 148 | // ---------------------------------------------------------------------------- |
| 149 | |
andrew@webrtc.org | 4484b83 | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 150 | #define NOT_SUPPORTED(stat) \ |
| 151 | LOG_F(LS_ERROR) << "not supported"; \ |
| 152 | stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \ |
| 153 | return -1; |
| 154 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 155 | #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400)) |
| 156 | #include <windows.h> |
| 157 | #include <stdio.h> |
| 158 | #define DEBUG_PRINT(...) \ |
| 159 | { \ |
| 160 | char msg[256]; \ |
| 161 | sprintf(msg, __VA_ARGS__); \ |
| 162 | OutputDebugStringA(msg); \ |
| 163 | } |
| 164 | #else |
| 165 | // special fix for visual 2003 |
| 166 | #define DEBUG_PRINT(exp) ((void)0) |
| 167 | #endif // defined(_DEBUG) && defined(_WIN32) |
| 168 | |
| 169 | #define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1; |
| 170 | |
| 171 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 172 | // Inline functions |
| 173 | // ---------------------------------------------------------------------------- |
| 174 | |
| 175 | namespace webrtc |
| 176 | { |
| 177 | |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 178 | inline int VoEId(int veId, int chId) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 179 | { |
| 180 | if (chId == -1) |
| 181 | { |
| 182 | const int dummyChannel(99); |
| 183 | return (int) ((veId << 16) + dummyChannel); |
| 184 | } |
| 185 | return (int) ((veId << 16) + chId); |
| 186 | } |
| 187 | |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 188 | inline int VoEModuleId(int veId, int chId) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 189 | { |
| 190 | return (int) ((veId << 16) + chId); |
| 191 | } |
| 192 | |
| 193 | // Convert module ID to internal VoE channel ID |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 194 | inline int VoEChannelId(int moduleId) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 195 | { |
| 196 | return (int) (moduleId & 0xffff); |
| 197 | } |
| 198 | |
pbos@webrtc.org | 5ab7b93 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 199 | } // namespace webrtc |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 200 | |
| 201 | // ---------------------------------------------------------------------------- |
| 202 | // Platform settings |
| 203 | // ---------------------------------------------------------------------------- |
| 204 | |
| 205 | // *** WINDOWS *** |
| 206 | |
| 207 | #if defined(_WIN32) |
| 208 | |
andrew@webrtc.org | 81c4d24 | 2013-09-09 17:50:10 +0000 | [diff] [blame] | 209 | #include <windows.h> |
| 210 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 211 | #pragma comment( lib, "winmm.lib" ) |
| 212 | |
| 213 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
| 214 | #pragma comment( lib, "ws2_32.lib" ) |
| 215 | #endif |
| 216 | |
| 217 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 218 | // Defines |
| 219 | // ---------------------------------------------------------------------------- |
| 220 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 221 | // Default device for Windows PC |
| 222 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \ |
| 223 | AudioDeviceModule::kDefaultCommunicationDevice |
| 224 | |
| 225 | #endif // #if (defined(_WIN32) |
| 226 | |
| 227 | // *** LINUX *** |
| 228 | |
| 229 | #ifdef WEBRTC_LINUX |
| 230 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 231 | #include <arpa/inet.h> |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 232 | #include <netinet/in.h> |
| 233 | #include <pthread.h> |
| 234 | #include <sys/socket.h> |
| 235 | #include <sys/types.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 236 | #ifndef QNX |
| 237 | #include <linux/net.h> |
| 238 | #ifndef ANDROID |
| 239 | #include <sys/soundcard.h> |
| 240 | #endif // ANDROID |
| 241 | #endif // QNX |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 242 | #include <errno.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 243 | #include <fcntl.h> |
| 244 | #include <sched.h> |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 245 | #include <stdio.h> |
| 246 | #include <stdlib.h> |
| 247 | #include <string.h> |
| 248 | #include <sys/ioctl.h> |
| 249 | #include <sys/stat.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 250 | #include <sys/time.h> |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 251 | #include <time.h> |
| 252 | #include <unistd.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 253 | |
| 254 | #define DWORD unsigned long int |
| 255 | #define WINAPI |
| 256 | #define LPVOID void * |
| 257 | #define FALSE 0 |
| 258 | #define TRUE 1 |
| 259 | #define UINT unsigned int |
| 260 | #define UCHAR unsigned char |
| 261 | #define TCHAR char |
| 262 | #ifdef QNX |
| 263 | #define _stricmp stricmp |
| 264 | #else |
| 265 | #define _stricmp strcasecmp |
| 266 | #endif |
| 267 | #define GetLastError() errno |
| 268 | #define WSAGetLastError() errno |
| 269 | #define LPCTSTR const char* |
| 270 | #define LPCSTR const char* |
| 271 | #define wsprintf sprintf |
| 272 | #define TEXT(a) a |
| 273 | #define _ftprintf fprintf |
| 274 | #define _tcslen strlen |
| 275 | #define FAR |
| 276 | #define __cdecl |
| 277 | #define LPSOCKADDR struct sockaddr * |
| 278 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 279 | // Default device for Linux and Android |
| 280 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0 |
| 281 | |
| 282 | #ifdef ANDROID |
| 283 | |
| 284 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 285 | // Defines |
| 286 | // ---------------------------------------------------------------------------- |
| 287 | |
| 288 | // Always excluded for Android builds |
| 289 | #undef WEBRTC_CODEC_ISAC |
| 290 | #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 291 | |
andrew@webrtc.org | 4484b83 | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 292 | #define ANDROID_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 293 | |
| 294 | #else // LINUX PC |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 295 | |
| 296 | // ---------------------------------------------------------------------------- |
| 297 | // Defines |
| 298 | // ---------------------------------------------------------------------------- |
| 299 | |
| 300 | #define ANDROID_NOT_SUPPORTED(stat) |
| 301 | |
| 302 | #endif // ANDROID - LINUX PC |
| 303 | |
| 304 | #else |
| 305 | #define ANDROID_NOT_SUPPORTED(stat) |
| 306 | #endif // #ifdef WEBRTC_LINUX |
| 307 | |
| 308 | // *** WEBRTC_MAC *** |
| 309 | // including iPhone |
| 310 | |
| 311 | #ifdef WEBRTC_MAC |
| 312 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 313 | #include <AudioUnit/AudioUnit.h> |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 314 | #include <arpa/inet.h> |
| 315 | #include <errno.h> |
| 316 | #include <fcntl.h> |
| 317 | #include <netinet/in.h> |
| 318 | #include <pthread.h> |
| 319 | #include <sched.h> |
| 320 | #include <stdio.h> |
| 321 | #include <stdlib.h> |
| 322 | #include <string.h> |
| 323 | #include <sys/socket.h> |
| 324 | #include <sys/stat.h> |
| 325 | #include <sys/time.h> |
| 326 | #include <sys/types.h> |
| 327 | #include <time.h> |
| 328 | #include <unistd.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 329 | #if !defined(WEBRTC_IOS) |
| 330 | #include <CoreServices/CoreServices.h> |
| 331 | #include <CoreAudio/CoreAudio.h> |
| 332 | #include <AudioToolbox/DefaultAudioOutput.h> |
| 333 | #include <AudioToolbox/AudioConverter.h> |
| 334 | #include <CoreAudio/HostTime.h> |
| 335 | #endif |
| 336 | |
| 337 | #define DWORD unsigned long int |
| 338 | #define WINAPI |
| 339 | #define LPVOID void * |
| 340 | #define FALSE 0 |
| 341 | #define TRUE 1 |
| 342 | #define SOCKADDR_IN struct sockaddr_in |
| 343 | #define UINT unsigned int |
| 344 | #define UCHAR unsigned char |
| 345 | #define TCHAR char |
| 346 | #define _stricmp strcasecmp |
| 347 | #define GetLastError() errno |
| 348 | #define WSAGetLastError() errno |
| 349 | #define LPCTSTR const char* |
| 350 | #define wsprintf sprintf |
| 351 | #define TEXT(a) a |
| 352 | #define _ftprintf fprintf |
| 353 | #define _tcslen strlen |
| 354 | #define FAR |
| 355 | #define __cdecl |
| 356 | #define LPSOCKADDR struct sockaddr * |
| 357 | #define LPCSTR const char* |
| 358 | #define ULONG unsigned long |
| 359 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 360 | // Default device for Mac and iPhone |
| 361 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0 |
| 362 | |
| 363 | // iPhone specific |
| 364 | #if defined(WEBRTC_IOS) |
| 365 | |
| 366 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 367 | // Defines |
| 368 | // ---------------------------------------------------------------------------- |
| 369 | |
| 370 | // Always excluded for iPhone builds |
| 371 | #undef WEBRTC_CODEC_ISAC |
| 372 | #undef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT |
| 373 | |
andrew@webrtc.org | 4484b83 | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 374 | #define IPHONE_NOT_SUPPORTED(stat) NOT_SUPPORTED(stat) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 375 | |
| 376 | #else // Non-iPhone |
| 377 | |
| 378 | // ---------------------------------------------------------------------------- |
| 379 | // Enumerators |
| 380 | // ---------------------------------------------------------------------------- |
| 381 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 382 | // ---------------------------------------------------------------------------- |
| 383 | // Defines |
| 384 | // ---------------------------------------------------------------------------- |
| 385 | |
| 386 | #define IPHONE_NOT_SUPPORTED(stat) |
| 387 | #endif |
| 388 | |
| 389 | #else |
| 390 | #define IPHONE_NOT_SUPPORTED(stat) |
| 391 | #endif // #ifdef WEBRTC_MAC |
| 392 | |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 393 | #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H |