Home | History | Annotate | Download | only in voice_engine
      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 
     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"
     23 
     24 // ----------------------------------------------------------------------------
     25 //  Enumerators
     26 // ----------------------------------------------------------------------------
     27 
     28 namespace webrtc {
     29 
     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 
     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 
     64 // Audio processing
     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
     78 const GainControl::Mode kDefaultRxAgcMode = GainControl::kAdaptiveDigital;
     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
    110 enum { kVoiceEngineMaxMinPlayoutDelayMs = 10000 };
    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 
    128 }  // namespace webrtc
    129 
    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 
    154 #define NOT_SUPPORTED(stat)                  \
    155   LOG_F(LS_ERROR) << "not supported";        \
    156   stat.SetLastError(VE_FUNC_NOT_SUPPORTED);  \
    157   return -1;
    158 
    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 // ----------------------------------------------------------------------------
    176 //  Inline functions
    177 // ----------------------------------------------------------------------------
    178 
    179 namespace webrtc
    180 {
    181 
    182 inline int VoEId(int veId, int chId)
    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 
    192 inline int VoEModuleId(int veId, int chId)
    193 {
    194     return (int) ((veId << 16) + chId);
    195 }
    196 
    197 // Convert module ID to internal VoE channel ID
    198 inline int VoEChannelId(int moduleId)
    199 {
    200     return (int) (moduleId & 0xffff);
    201 }
    202 
    203 }  // namespace webrtc
    204 
    205 // ----------------------------------------------------------------------------
    206 //  Platform settings
    207 // ----------------------------------------------------------------------------
    208 
    209 // *** WINDOWS ***
    210 
    211 #if defined(_WIN32)
    212 
    213   #include <windows.h>
    214 
    215   #pragma comment( lib, "winmm.lib" )
    216 
    217   #ifndef WEBRTC_EXTERNAL_TRANSPORT
    218     #pragma comment( lib, "ws2_32.lib" )
    219   #endif
    220 
    221 // ----------------------------------------------------------------------------
    222 //  Defines
    223 // ----------------------------------------------------------------------------
    224 
    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 
    235 #include <arpa/inet.h>
    236 #include <netinet/in.h>
    237 #include <pthread.h>
    238 #include <sys/socket.h>
    239 #include <sys/types.h>
    240 #ifndef QNX
    241   #include <linux/net.h>
    242 #ifndef ANDROID
    243   #include <sys/soundcard.h>
    244 #endif // ANDROID
    245 #endif // QNX
    246 #include <errno.h>
    247 #include <fcntl.h>
    248 #include <sched.h>
    249 #include <stdio.h>
    250 #include <stdlib.h>
    251 #include <string.h>
    252 #include <sys/ioctl.h>
    253 #include <sys/stat.h>
    254 #include <sys/time.h>
    255 #include <time.h>
    256 #include <unistd.h>
    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 
    283 // Default device for Linux and Android
    284 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
    285 
    286 #endif  // #ifdef WEBRTC_LINUX
    287 
    288 // *** WEBRTC_MAC ***
    289 // including iPhone
    290 
    291 #ifdef WEBRTC_MAC
    292 
    293 #include <AudioUnit/AudioUnit.h>
    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>
    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 
    340 // Default device for Mac and iPhone
    341 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
    342 #endif  // #ifdef WEBRTC_MAC
    343 
    344 #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H
    345