Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / voice_engine / voice_engine_defines.h
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 //  Macros
132 // ----------------------------------------------------------------------------
133
134 #define NOT_SUPPORTED(stat)                  \
135   LOG_F(LS_ERROR) << "not supported";        \
136   stat.SetLastError(VE_FUNC_NOT_SUPPORTED);  \
137   return -1;
138
139 #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
140   #include <windows.h>
141   #include <stdio.h>
142   #define DEBUG_PRINT(...)      \
143   {                             \
144     char msg[256];              \
145     sprintf(msg, __VA_ARGS__);  \
146     OutputDebugStringA(msg);    \
147   }
148 #else
149   // special fix for visual 2003
150   #define DEBUG_PRINT(exp)      ((void)0)
151 #endif  // defined(_DEBUG) && defined(_WIN32)
152
153 #define CHECK_CHANNEL(channel)  if (CheckChannel(channel) == -1) return -1;
154
155 // ----------------------------------------------------------------------------
156 //  Inline functions
157 // ----------------------------------------------------------------------------
158
159 namespace webrtc
160 {
161
162 inline int VoEId(int veId, int chId)
163 {
164     if (chId == -1)
165     {
166         const int dummyChannel(99);
167         return (int) ((veId << 16) + dummyChannel);
168     }
169     return (int) ((veId << 16) + chId);
170 }
171
172 inline int VoEModuleId(int veId, int chId)
173 {
174     return (int) ((veId << 16) + chId);
175 }
176
177 // Convert module ID to internal VoE channel ID
178 inline int VoEChannelId(int moduleId)
179 {
180     return (int) (moduleId & 0xffff);
181 }
182
183 }  // namespace webrtc
184
185 // ----------------------------------------------------------------------------
186 //  Platform settings
187 // ----------------------------------------------------------------------------
188
189 // *** WINDOWS ***
190
191 #if defined(_WIN32)
192
193   #include <windows.h>
194
195   #pragma comment( lib, "winmm.lib" )
196
197   #ifndef WEBRTC_EXTERNAL_TRANSPORT
198     #pragma comment( lib, "ws2_32.lib" )
199   #endif
200
201 // ----------------------------------------------------------------------------
202 //  Defines
203 // ----------------------------------------------------------------------------
204
205 // Default device for Windows PC
206   #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE \
207     AudioDeviceModule::kDefaultCommunicationDevice
208
209 #endif  // #if (defined(_WIN32)
210
211 // *** LINUX ***
212
213 #ifdef WEBRTC_LINUX
214
215 #include <arpa/inet.h>
216 #include <netinet/in.h>
217 #include <pthread.h>
218 #include <sys/socket.h>
219 #include <sys/types.h>
220 #ifndef QNX
221   #include <linux/net.h>
222 #ifndef ANDROID
223   #include <sys/soundcard.h>
224 #endif // ANDROID
225 #endif // QNX
226 #include <errno.h>
227 #include <fcntl.h>
228 #include <sched.h>
229 #include <stdio.h>
230 #include <stdlib.h>
231 #include <string.h>
232 #include <sys/ioctl.h>
233 #include <sys/stat.h>
234 #include <sys/time.h>
235 #include <time.h>
236 #include <unistd.h>
237
238 #define DWORD unsigned long int
239 #define WINAPI
240 #define LPVOID void *
241 #define FALSE 0
242 #define TRUE 1
243 #define UINT unsigned int
244 #define UCHAR unsigned char
245 #define TCHAR char
246 #ifdef QNX
247 #define _stricmp stricmp
248 #else
249 #define _stricmp strcasecmp
250 #endif
251 #define GetLastError() errno
252 #define WSAGetLastError() errno
253 #define LPCTSTR const char*
254 #define LPCSTR const char*
255 #define wsprintf sprintf
256 #define TEXT(a) a
257 #define _ftprintf fprintf
258 #define _tcslen strlen
259 #define FAR
260 #define __cdecl
261 #define LPSOCKADDR struct sockaddr *
262
263 // Default device for Linux and Android
264 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
265
266 #endif  // #ifdef WEBRTC_LINUX
267
268 // *** WEBRTC_MAC ***
269 // including iPhone
270
271 #ifdef WEBRTC_MAC
272
273 #include <AudioUnit/AudioUnit.h>
274 #include <arpa/inet.h>
275 #include <errno.h>
276 #include <fcntl.h>
277 #include <netinet/in.h>
278 #include <pthread.h>
279 #include <sched.h>
280 #include <stdio.h>
281 #include <stdlib.h>
282 #include <string.h>
283 #include <sys/socket.h>
284 #include <sys/stat.h>
285 #include <sys/time.h>
286 #include <sys/types.h>
287 #include <time.h>
288 #include <unistd.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>
295 #endif
296
297 #define DWORD unsigned long int
298 #define WINAPI
299 #define LPVOID void *
300 #define FALSE 0
301 #define TRUE 1
302 #define SOCKADDR_IN struct sockaddr_in
303 #define UINT unsigned int
304 #define UCHAR unsigned char
305 #define TCHAR char
306 #define _stricmp strcasecmp
307 #define GetLastError() errno
308 #define WSAGetLastError() errno
309 #define LPCTSTR const char*
310 #define wsprintf sprintf
311 #define TEXT(a) a
312 #define _ftprintf fprintf
313 #define _tcslen strlen
314 #define FAR
315 #define __cdecl
316 #define LPSOCKADDR struct sockaddr *
317 #define LPCSTR const char*
318 #define ULONG unsigned long
319
320 // Default device for Mac and iPhone
321 #define WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE 0
322 #endif  // #ifdef WEBRTC_MAC
323
324 #endif // WEBRTC_VOICE_ENGINE_VOICE_ENGINE_DEFINES_H