andrew@webrtc.org | b015cbe | 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 | 81b54fe | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 19 | #include "webrtc/common_types.h" |
| 20 | #include "webrtc/engine_configurations.h" |
andrew@webrtc.org | b79627b | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
andrew@webrtc.org | 81b54fe | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 22 | #include "webrtc/system_wrappers/interface/logging.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | // Enumerators |
| 26 | // ---------------------------------------------------------------------------- |
| 27 | |
andrew@webrtc.org | 8339bd1 | 2013-02-01 23:42:44 +0000 | [diff] [blame] | 28 | namespace webrtc { |
| 29 | |
andrew@webrtc.org | f7c73b5 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 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; |
| 33 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 34 | // VolumeControl |
| 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; |
| 45 | |
| 46 | // DTMF |
| 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 |
| 56 | // telephone events |
| 57 | enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet |
| 58 | |
| 59 | enum { kVoiceEngineMaxModuleVersionSize = 960 }; |
| 60 | |
| 61 | // Base |
| 62 | enum { kVoiceEngineVersionMaxMessageSize = 1024 }; |
| 63 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 64 | // Audio processing |
andrew@webrtc.org | b79627b | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 65 | const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate; |
| 66 | const GainControl::Mode kDefaultAgcMode = |
| 67 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 68 | GainControl::kAdaptiveDigital; |
| 69 | #else |
| 70 | GainControl::kAdaptiveAnalog; |
| 71 | #endif |
| 72 | const bool kDefaultAgcState = |
| 73 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 74 | false; |
| 75 | #else |
| 76 | true; |
| 77 | #endif |
andrew@webrtc.org | e06943f | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 78 | const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 79 | |
| 80 | // Codec |
| 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 }; |
| 105 | |
| 106 | // VideoSync |
| 107 | // Lowest minimum playout delay |
| 108 | enum { kVoiceEngineMinMinPlayoutDelayMs = 0 }; |
| 109 | // Highest minimum playout delay |
niklas.enbom@webrtc.org | db32ab0 | 2013-01-17 22:25:49 +0000 | [diff] [blame] | 110 | enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 111 | |
| 112 | // Network |
| 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 }; |
| 121 | |
| 122 | // RTP/RTCP |
| 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 }; |
| 127 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 128 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 129 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 130 | // ---------------------------------------------------------------------------- |
| 131 | // Build information macros |
| 132 | // ---------------------------------------------------------------------------- |
| 133 | |
| 134 | #if defined(_DEBUG) |
| 135 | #define BUILDMODE "d" |
| 136 | #elif defined(DEBUG) |
| 137 | #define BUILDMODE "d" |
| 138 | #elif defined(NDEBUG) |
| 139 | #define BUILDMODE "r" |
| 140 | #else |
| 141 | #define BUILDMODE "?" |
| 142 | #endif |
| 143 | |
| 144 | #define BUILDTIME __TIME__ |
| 145 | #define BUILDDATE __DATE__ |
| 146 | |
| 147 | // Example: "Oct 10 2002 12:05:30 r" |
| 148 | #define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE |
| 149 | |
| 150 | // ---------------------------------------------------------------------------- |
| 151 | // Macros |
| 152 | // ---------------------------------------------------------------------------- |
| 153 | |
andrew@webrtc.org | 81b54fe | 2013-02-05 21:23:39 +0000 | [diff] [blame] | 154 | #define NOT_SUPPORTED(stat) \ |
| 155 | LOG_F(LS_ERROR) << "not supported"; \ |
| 156 | stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \ |
| 157 | return -1; |
| 158 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 159 | #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400)) |
| 160 | #include <windows.h> |
| 161 | #include <stdio.h> |
| 162 | #define DEBUG_PRINT(...) \ |
| 163 | { \ |
| 164 | char msg[256]; \ |
| 165 | sprintf(msg, __VA_ARGS__); \ |
| 166 | OutputDebugStringA(msg); \ |
| 167 | } |
| 168 | #else |
| 169 | // special fix for visual 2003 |
| 170 | #define DEBUG_PRINT(exp) ((void)0) |
| 171 | #endif // defined(_DEBUG) && defined(_WIN32) |
| 172 | |
| 173 | #define CHECK_CHANNEL(channel) if (CheckChannel(channel) == -1) return -1; |
| 174 | |
| 175 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 176 | // Inline functions |
| 177 | // ---------------------------------------------------------------------------- |
| 178 | |
| 179 | namespace webrtc |
| 180 | { |
| 181 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 182 | inline int VoEId(int veId, int chId) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 183 | { |
| 184 | if (chId == -1) |
| 185 | { |
| 186 | const int dummyChannel(99); |
| 187 | return (int) ((veId << 16) + dummyChannel); |
| 188 | } |
| 189 | return (int) ((veId << 16) + chId); |
| 190 | } |
| 191 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 192 | inline int VoEModuleId(int veId, int chId) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 193 | { |
| 194 | return (int) ((veId << 16) + chId); |
| 195 | } |
| 196 | |
| 197 | // Convert module ID to internal VoE channel ID |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 198 | inline int VoEChannelId(int moduleId) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 199 | { |
| 200 | return (int) (moduleId & 0xffff); |
| 201 | } |
| 202 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 203 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 204 | |
| 205 | // ---------------------------------------------------------------------------- |
| 206 | // Platform settings |
| 207 | // ---------------------------------------------------------------------------- |
| 208 | |
| 209 | // *** WINDOWS *** |
| 210 | |
| 211 | #if defined(_WIN32) |
| 212 | |
andrew@webrtc.org | 5cf83f4 | 2013-09-09 17:50:10 +0000 | [diff] [blame] | 213 | #include <windows.h> |
| 214 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 215 | #pragma comment( lib, "winmm.lib" ) |
| 216 | |
| 217 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
| 218 | #pragma comment( lib, "ws2_32.lib" ) |
| 219 | #endif |
| 220 | |
| 221 | // ---------------------------------------------------------------------------- |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 222 | // Defines |
| 223 | // ---------------------------------------------------------------------------- |
| 224 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 225 | // Default device for Windows PC |
| 226 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \ |
| 227 | AudioDeviceModule::kDefaultCommunicationDevice |
| 228 | |
| 229 | #endif // #if (defined(_WIN32) |
| 230 | |
| 231 | // *** LINUX *** |
| 232 | |
| 233 | #ifdef WEBRTC_LINUX |
| 234 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 235 | #include <arpa/inet.h> |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 236 | #include <netinet/in.h> |
| 237 | #include <pthread.h> |
| 238 | #include <sys/socket.h> |
| 239 | #include <sys/types.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 240 | #ifndef QNX |
| 241 | #include <linux/net.h> |
| 242 | #ifndef ANDROID |
| 243 | #include <sys/soundcard.h> |
| 244 | #endif // ANDROID |
| 245 | #endif // QNX |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 246 | #include <errno.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 247 | #include <fcntl.h> |
| 248 | #include <sched.h> |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 249 | #include <stdio.h> |
| 250 | #include <stdlib.h> |
| 251 | #include <string.h> |
| 252 | #include <sys/ioctl.h> |
| 253 | #include <sys/stat.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 254 | #include <sys/time.h> |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 255 | #include <time.h> |
| 256 | #include <unistd.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 257 | |
| 258 | #define DWORD unsigned long int |
| 259 | #define WINAPI |
| 260 | #define LPVOID void * |
| 261 | #define FALSE 0 |
| 262 | #define TRUE 1 |
| 263 | #define UINT unsigned int |
| 264 | #define UCHAR unsigned char |
| 265 | #define TCHAR char |
| 266 | #ifdef QNX |
| 267 | #define _stricmp stricmp |
| 268 | #else |
| 269 | #define _stricmp strcasecmp |
| 270 | #endif |
| 271 | #define GetLastError() errno |
| 272 | #define WSAGetLastError() errno |
| 273 | #define LPCTSTR const char* |
| 274 | #define LPCSTR const char* |
| 275 | #define wsprintf sprintf |
| 276 | #define TEXT(a) a |
| 277 | #define _ftprintf fprintf |
| 278 | #define _tcslen strlen |
| 279 | #define FAR |
| 280 | #define __cdecl |
| 281 | #define LPSOCKADDR struct sockaddr * |
| 282 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 283 | // Default device for Linux and Android |
| 284 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0 |
| 285 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 286 | #endif // #ifdef WEBRTC_LINUX |
| 287 | |
| 288 | // *** WEBRTC_MAC *** |
| 289 | // including iPhone |
| 290 | |
| 291 | #ifdef WEBRTC_MAC |
| 292 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 293 | #include <AudioUnit/AudioUnit.h> |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 294 | #include <arpa/inet.h> |
| 295 | #include <errno.h> |
| 296 | #include <fcntl.h> |
| 297 | #include <netinet/in.h> |
| 298 | #include <pthread.h> |
| 299 | #include <sched.h> |
| 300 | #include <stdio.h> |
| 301 | #include <stdlib.h> |
| 302 | #include <string.h> |
| 303 | #include <sys/socket.h> |
| 304 | #include <sys/stat.h> |
| 305 | #include <sys/time.h> |
| 306 | #include <sys/types.h> |
| 307 | #include <time.h> |
| 308 | #include <unistd.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 309 | #if !defined(WEBRTC_IOS) |
| 310 | #include <CoreServices/CoreServices.h> |
| 311 | #include <CoreAudio/CoreAudio.h> |
| 312 | #include <AudioToolbox/DefaultAudioOutput.h> |
| 313 | #include <AudioToolbox/AudioConverter.h> |
| 314 | #include <CoreAudio/HostTime.h> |
| 315 | #endif |
| 316 | |
| 317 | #define DWORD unsigned long int |
| 318 | #define WINAPI |
| 319 | #define LPVOID void * |
| 320 | #define FALSE 0 |
| 321 | #define TRUE 1 |
| 322 | #define SOCKADDR_IN struct sockaddr_in |
| 323 | #define UINT unsigned int |
| 324 | #define UCHAR unsigned char |
| 325 | #define TCHAR char |
| 326 | #define _stricmp strcasecmp |
| 327 | #define GetLastError() errno |
| 328 | #define WSAGetLastError() errno |
| 329 | #define LPCTSTR const char* |
| 330 | #define wsprintf sprintf |
| 331 | #define TEXT(a) a |
| 332 | #define _ftprintf fprintf |
| 333 | #define _tcslen strlen |
| 334 | #define FAR |
| 335 | #define __cdecl |
| 336 | #define LPSOCKADDR struct sockaddr * |
| 337 | #define LPCSTR const char* |
| 338 | #define ULONG unsigned long |
| 339 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 340 | // Default device for Mac and iPhone |
| 341 | #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 342 | #endif // #ifdef WEBRTC_MAC |
| 343 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 344 | #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H |