1 /* 2 * Copyright (c) 2011 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 #ifndef WEBRTC_COMMON_TYPES_H 12 #define WEBRTC_COMMON_TYPES_H 13 14 #include "typedefs.h" 15 16 #ifdef WEBRTC_EXPORT 17 #define WEBRTC_DLLEXPORT _declspec(dllexport) 18 #elif WEBRTC_DLL 19 #define WEBRTC_DLLEXPORT _declspec(dllimport) 20 #else 21 #define WEBRTC_DLLEXPORT 22 #endif 23 24 #ifndef NULL 25 #define NULL 0 26 #endif 27 28 namespace webrtc { 29 30 class InStream 31 { 32 public: 33 virtual int Read(void *buf,int len) = 0; Rewind()34 virtual int Rewind() {return -1;} ~InStream()35 virtual ~InStream() {} 36 protected: InStream()37 InStream() {} 38 }; 39 40 class OutStream 41 { 42 public: 43 virtual bool Write(const void *buf,int len) = 0; Rewind()44 virtual int Rewind() {return -1;} ~OutStream()45 virtual ~OutStream() {} 46 protected: OutStream()47 OutStream() {} 48 }; 49 50 enum TraceModule 51 { 52 // not a module, triggered from the engine code 53 kTraceVoice = 0x0001, 54 // not a module, triggered from the engine code 55 kTraceVideo = 0x0002, 56 // not a module, triggered from the utility code 57 kTraceUtility = 0x0003, 58 kTraceRtpRtcp = 0x0004, 59 kTraceTransport = 0x0005, 60 kTraceSrtp = 0x0006, 61 kTraceAudioCoding = 0x0007, 62 kTraceAudioMixerServer = 0x0008, 63 kTraceAudioMixerClient = 0x0009, 64 kTraceFile = 0x000a, 65 kTraceAudioProcessing = 0x000b, 66 kTraceVideoCoding = 0x0010, 67 kTraceVideoMixer = 0x0011, 68 kTraceAudioDevice = 0x0012, 69 kTraceVideoRenderer = 0x0014, 70 kTraceVideoCapture = 0x0015, 71 kTraceVideoPreocessing = 0x0016 72 }; 73 74 enum TraceLevel 75 { 76 kTraceNone = 0x0000, // no trace 77 kTraceStateInfo = 0x0001, 78 kTraceWarning = 0x0002, 79 kTraceError = 0x0004, 80 kTraceCritical = 0x0008, 81 kTraceApiCall = 0x0010, 82 kTraceDefault = 0x00ff, 83 84 kTraceModuleCall = 0x0020, 85 kTraceMemory = 0x0100, // memory info 86 kTraceTimer = 0x0200, // timing info 87 kTraceStream = 0x0400, // "continuous" stream of data 88 89 // used for debug purposes 90 kTraceDebug = 0x0800, // debug 91 kTraceInfo = 0x1000, // debug info 92 93 kTraceAll = 0xffff 94 }; 95 96 // External Trace API 97 class TraceCallback 98 { 99 public: 100 virtual void Print(const TraceLevel level, 101 const char *traceString, 102 const int length) = 0; 103 protected: ~TraceCallback()104 virtual ~TraceCallback() {} TraceCallback()105 TraceCallback() {} 106 }; 107 108 109 enum FileFormats 110 { 111 kFileFormatWavFile = 1, 112 kFileFormatCompressedFile = 2, 113 kFileFormatAviFile = 3, 114 kFileFormatPreencodedFile = 4, 115 kFileFormatPcm16kHzFile = 7, 116 kFileFormatPcm8kHzFile = 8, 117 kFileFormatPcm32kHzFile = 9 118 }; 119 120 121 enum ProcessingTypes 122 { 123 kPlaybackPerChannel = 0, 124 kPlaybackAllChannelsMixed, 125 kRecordingPerChannel, 126 kRecordingAllChannelsMixed 127 }; 128 129 // Encryption enums 130 enum CipherTypes 131 { 132 kCipherNull = 0, 133 kCipherAes128CounterMode = 1 134 }; 135 136 enum AuthenticationTypes 137 { 138 kAuthNull = 0, 139 kAuthHmacSha1 = 3 140 }; 141 142 enum SecurityLevels 143 { 144 kNoProtection = 0, 145 kEncryption = 1, 146 kAuthentication = 2, 147 kEncryptionAndAuthentication = 3 148 }; 149 150 class Encryption 151 { 152 public: 153 virtual void encrypt( 154 int channel_no, 155 unsigned char* in_data, 156 unsigned char* out_data, 157 int bytes_in, 158 int* bytes_out) = 0; 159 160 virtual void decrypt( 161 int channel_no, 162 unsigned char* in_data, 163 unsigned char* out_data, 164 int bytes_in, 165 int* bytes_out) = 0; 166 167 virtual void encrypt_rtcp( 168 int channel_no, 169 unsigned char* in_data, 170 unsigned char* out_data, 171 int bytes_in, 172 int* bytes_out) = 0; 173 174 virtual void decrypt_rtcp( 175 int channel_no, 176 unsigned char* in_data, 177 unsigned char* out_data, 178 int bytes_in, 179 int* bytes_out) = 0; 180 181 protected: ~Encryption()182 virtual ~Encryption() {} Encryption()183 Encryption() {} 184 }; 185 186 // External transport callback interface 187 class Transport 188 { 189 public: 190 virtual int SendPacket(int channel, const void *data, int len) = 0; 191 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0; 192 193 protected: ~Transport()194 virtual ~Transport() {} Transport()195 Transport() {} 196 }; 197 198 // ================================================================== 199 // Voice specific types 200 // ================================================================== 201 202 // Each codec supported can be described by this structure. 203 struct CodecInst 204 { 205 int pltype; 206 char plname[32]; 207 int plfreq; 208 int pacsize; 209 int channels; 210 int rate; 211 }; 212 213 enum FrameType 214 { 215 kFrameEmpty = 0, 216 kAudioFrameSpeech = 1, 217 kAudioFrameCN = 2, 218 kVideoFrameKey = 3, // independent frame 219 kVideoFrameDelta = 4, // depends on the previus frame 220 kVideoFrameGolden = 5, // depends on a old known previus frame 221 kVideoFrameAltRef = 6 222 }; 223 224 // RTP 225 enum {kRtpCsrcSize = 15}; // RFC 3550 page 13 226 227 enum RTPDirections 228 { 229 kRtpIncoming = 0, 230 kRtpOutgoing 231 }; 232 233 enum PayloadFrequencies 234 { 235 kFreq8000Hz = 8000, 236 kFreq16000Hz = 16000, 237 kFreq32000Hz = 32000 238 }; 239 240 enum VadModes // degree of bandwidth reduction 241 { 242 kVadConventional = 0, // lowest reduction 243 kVadAggressiveLow, 244 kVadAggressiveMid, 245 kVadAggressiveHigh // highest reduction 246 }; 247 248 struct NetworkStatistics // NETEQ statistics 249 { 250 // current jitter buffer size in ms 251 WebRtc_UWord16 currentBufferSize; 252 // preferred (optimal) buffer size in ms 253 WebRtc_UWord16 preferredBufferSize; 254 // loss rate (network + late) in percent (in Q14) 255 WebRtc_UWord16 currentPacketLossRate; 256 // late loss rate in percent (in Q14) 257 WebRtc_UWord16 currentDiscardRate; 258 // fraction (of original stream) of synthesized speech inserted through 259 // expansion (in Q14) 260 WebRtc_UWord16 currentExpandRate; 261 // fraction of synthesized speech inserted through pre-emptive expansion 262 // (in Q14) 263 WebRtc_UWord16 currentPreemptiveRate; 264 // fraction of data removed through acceleration (in Q14) 265 WebRtc_UWord16 currentAccelerateRate; 266 }; 267 268 struct JitterStatistics 269 { 270 // smallest Jitter Buffer size during call in ms 271 WebRtc_UWord32 jbMinSize; 272 // largest Jitter Buffer size during call in ms 273 WebRtc_UWord32 jbMaxSize; 274 // the average JB size, measured over time - ms 275 WebRtc_UWord32 jbAvgSize; 276 // number of times the Jitter Buffer changed (using Accelerate or 277 // Pre-emptive Expand) 278 WebRtc_UWord32 jbChangeCount; 279 // amount (in ms) of audio data received late 280 WebRtc_UWord32 lateLossMs; 281 // milliseconds removed to reduce jitter buffer size 282 WebRtc_UWord32 accelerateMs; 283 // milliseconds discarded through buffer flushing 284 WebRtc_UWord32 flushedMs; 285 // milliseconds of generated silence 286 WebRtc_UWord32 generatedSilentMs; 287 // milliseconds of synthetic audio data (non-background noise) 288 WebRtc_UWord32 interpolatedVoiceMs; 289 // milliseconds of synthetic audio data (background noise level) 290 WebRtc_UWord32 interpolatedSilentMs; 291 // count of tiny expansions in output audio 292 WebRtc_UWord32 countExpandMoreThan120ms; 293 // count of small expansions in output audio 294 WebRtc_UWord32 countExpandMoreThan250ms; 295 // count of medium expansions in output audio 296 WebRtc_UWord32 countExpandMoreThan500ms; 297 // count of long expansions in output audio 298 WebRtc_UWord32 countExpandMoreThan2000ms; 299 // duration of longest audio drop-out 300 WebRtc_UWord32 longestExpandDurationMs; 301 // count of times we got small network outage (inter-arrival time in 302 // [500, 1000) ms) 303 WebRtc_UWord32 countIAT500ms; 304 // count of times we got medium network outage (inter-arrival time in 305 // [1000, 2000) ms) 306 WebRtc_UWord32 countIAT1000ms; 307 // count of times we got large network outage (inter-arrival time >= 308 // 2000 ms) 309 WebRtc_UWord32 countIAT2000ms; 310 // longest packet inter-arrival time in ms 311 WebRtc_UWord32 longestIATms; 312 // min time incoming Packet "waited" to be played 313 WebRtc_UWord32 minPacketDelayMs; 314 // max time incoming Packet "waited" to be played 315 WebRtc_UWord32 maxPacketDelayMs; 316 // avg time incoming Packet "waited" to be played 317 WebRtc_UWord32 avgPacketDelayMs; 318 }; 319 320 typedef struct 321 { 322 int min; // minumum 323 int max; // maximum 324 int average; // average 325 } StatVal; 326 327 typedef struct // All levels are reported in dBm0 328 { 329 StatVal speech_rx; // long-term speech levels on receiving side 330 StatVal speech_tx; // long-term speech levels on transmitting side 331 StatVal noise_rx; // long-term noise/silence levels on receiving side 332 StatVal noise_tx; // long-term noise/silence levels on transmitting side 333 } LevelStatistics; 334 335 typedef struct // All levels are reported in dB 336 { 337 StatVal erl; // Echo Return Loss 338 StatVal erle; // Echo Return Loss Enhancement 339 StatVal rerl; // RERL = ERL + ERLE 340 // Echo suppression inside EC at the point just before its NLP 341 StatVal a_nlp; 342 } EchoStatistics; 343 344 enum TelephoneEventDetectionMethods 345 { 346 kInBand = 0, 347 kOutOfBand = 1, 348 kInAndOutOfBand = 2 349 }; 350 351 enum NsModes // type of Noise Suppression 352 { 353 kNsUnchanged = 0, // previously set mode 354 kNsDefault, // platform default 355 kNsConference, // conferencing default 356 kNsLowSuppression, // lowest suppression 357 kNsModerateSuppression, 358 kNsHighSuppression, 359 kNsVeryHighSuppression, // highest suppression 360 }; 361 362 enum AgcModes // type of Automatic Gain Control 363 { 364 kAgcUnchanged = 0, // previously set mode 365 kAgcDefault, // platform default 366 // adaptive mode for use when analog volume control exists (e.g. for 367 // PC softphone) 368 kAgcAdaptiveAnalog, 369 // scaling takes place in the digital domain (e.g. for conference servers 370 // and embedded devices) 371 kAgcAdaptiveDigital, 372 // can be used on embedded devices where the the capture signal is level 373 // is predictable 374 kAgcFixedDigital 375 }; 376 377 // EC modes 378 enum EcModes // type of Echo Control 379 { 380 kEcUnchanged = 0, // previously set mode 381 kEcDefault, // platform default 382 kEcConference, // conferencing default (aggressive AEC) 383 kEcAec, // Acoustic Echo Cancellation 384 kEcAecm, // AEC mobile 385 }; 386 387 // AECM modes 388 enum AecmModes // mode of AECM 389 { 390 kAecmQuietEarpieceOrHeadset = 0, 391 // Quiet earpiece or headset use 392 kAecmEarpiece, // most earpiece use 393 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use 394 kAecmSpeakerphone, // most speakerphone use (default) 395 kAecmLoudSpeakerphone // Loud speakerphone 396 }; 397 398 // AGC configuration 399 typedef struct 400 { 401 unsigned short targetLeveldBOv; 402 unsigned short digitalCompressionGaindB; 403 bool limiterEnable; 404 } AgcConfig; // AGC configuration parameters 405 406 enum StereoChannel 407 { 408 kStereoLeft = 0, 409 kStereoRight, 410 kStereoBoth 411 }; 412 413 // Audio device layers 414 enum AudioLayers 415 { 416 kAudioPlatformDefault = 0, 417 kAudioWindowsWave = 1, 418 kAudioWindowsCore = 2, 419 kAudioLinuxAlsa = 3, 420 kAudioLinuxPulse = 4 421 }; 422 423 enum NetEqModes // NetEQ playout configurations 424 { 425 // Optimized trade-off between low delay and jitter robustness for two-way 426 // communication. 427 kNetEqDefault = 0, 428 // Improved jitter robustness at the cost of increased delay. Can be 429 // used in one-way communication. 430 kNetEqStreaming = 1, 431 // Optimzed for decodability of fax signals rather than for perceived audio 432 // quality. 433 kNetEqFax = 2, 434 }; 435 436 enum NetEqBgnModes // NetEQ Background Noise (BGN) configurations 437 { 438 // BGN is always on and will be generated when the incoming RTP stream 439 // stops (default). 440 kBgnOn = 0, 441 // The BGN is faded to zero (complete silence) after a few seconds. 442 kBgnFade = 1, 443 // BGN is not used at all. Silence is produced after speech extrapolation 444 // has faded. 445 kBgnOff = 2, 446 }; 447 448 enum OnHoldModes // On Hold direction 449 { 450 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state. 451 kHoldSendOnly, // Put only sending in on-hold state. 452 kHoldPlayOnly // Put only playing in on-hold state. 453 }; 454 455 enum AmrMode 456 { 457 kRfc3267BwEfficient = 0, 458 kRfc3267OctetAligned = 1, 459 kRfc3267FileStorage = 2, 460 }; 461 462 // ================================================================== 463 // Video specific types 464 // ================================================================== 465 466 // Raw video types 467 enum RawVideoType 468 { 469 kVideoI420 = 0, 470 kVideoYV12 = 1, 471 kVideoYUY2 = 2, 472 kVideoUYVY = 3, 473 kVideoIYUV = 4, 474 kVideoARGB = 5, 475 kVideoRGB24 = 6, 476 kVideoRGB565 = 7, 477 kVideoARGB4444 = 8, 478 kVideoARGB1555 = 9, 479 kVideoMJPEG = 10, 480 kVideoNV12 = 11, 481 kVideoNV21 = 12, 482 kVideoUnknown = 99 483 }; 484 485 // Video codec 486 enum { kConfigParameterSize = 128}; 487 enum { kPayloadNameSize = 32}; 488 489 // H.263 specific 490 struct VideoCodecH263 491 { 492 char quality; 493 }; 494 495 // H.264 specific 496 enum H264Packetization 497 { 498 kH264SingleMode = 0, 499 kH264NonInterleavedMode = 1 500 }; 501 502 enum VideoCodecComplexity 503 { 504 kComplexityNormal = 0, 505 kComplexityHigh = 1, 506 kComplexityHigher = 2, 507 kComplexityMax = 3 508 }; 509 510 enum VideoCodecProfile 511 { 512 kProfileBase = 0x00, 513 kProfileMain = 0x01 514 }; 515 516 struct VideoCodecH264 517 { 518 H264Packetization packetization; 519 VideoCodecComplexity complexity; 520 VideoCodecProfile profile; 521 char level; 522 char quality; 523 524 bool useFMO; 525 526 unsigned char configParameters[kConfigParameterSize]; 527 unsigned char configParametersSize; 528 }; 529 530 // VP8 specific 531 struct VideoCodecVP8 532 { 533 bool pictureLossIndicationOn; 534 bool feedbackModeOn; 535 VideoCodecComplexity complexity; 536 }; 537 538 // MPEG-4 specific 539 struct VideoCodecMPEG4 540 { 541 unsigned char configParameters[kConfigParameterSize]; 542 unsigned char configParametersSize; 543 char level; 544 }; 545 546 // Unknown specific 547 struct VideoCodecGeneric 548 { 549 }; 550 551 // Video codec types 552 enum VideoCodecType 553 { 554 kVideoCodecH263, 555 kVideoCodecH264, 556 kVideoCodecVP8, 557 kVideoCodecMPEG4, 558 kVideoCodecI420, 559 kVideoCodecRED, 560 kVideoCodecULPFEC, 561 kVideoCodecUnknown 562 }; 563 564 union VideoCodecUnion 565 { 566 VideoCodecH263 H263; 567 VideoCodecH264 H264; 568 VideoCodecVP8 VP8; 569 VideoCodecMPEG4 MPEG4; 570 VideoCodecGeneric Generic; 571 }; 572 573 // Common video codec properties 574 struct VideoCodec 575 { 576 VideoCodecType codecType; 577 char plName[kPayloadNameSize]; 578 unsigned char plType; 579 580 unsigned short width; 581 unsigned short height; 582 583 unsigned int startBitrate; 584 unsigned int maxBitrate; 585 unsigned int minBitrate; 586 unsigned char maxFramerate; 587 588 VideoCodecUnion codecSpecific; 589 590 unsigned int qpMax; 591 }; 592 593 } // namespace webrtc 594 595 #endif // WEBRTC_COMMON_TYPES_H 596