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; 34 virtual int Rewind() {return -1;} 35 virtual ~InStream() {} 36 protected: 37 InStream() {} 38 }; 39 40 class OutStream 41 { 42 public: 43 virtual bool Write(const void *buf,int len) = 0; 44 virtual int Rewind() {return -1;} 45 virtual ~OutStream() {} 46 protected: 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: 104 virtual ~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: 182 virtual ~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: 194 virtual ~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 // adding extra delay due to "peaky jitter" 255 bool jitterPeaksFound; 256 // loss rate (network + late) in percent (in Q14) 257 WebRtc_UWord16 currentPacketLossRate; 258 // late loss rate in percent (in Q14) 259 WebRtc_UWord16 currentDiscardRate; 260 // fraction (of original stream) of synthesized speech inserted through 261 // expansion (in Q14) 262 WebRtc_UWord16 currentExpandRate; 263 // fraction of synthesized speech inserted through pre-emptive expansion 264 // (in Q14) 265 WebRtc_UWord16 currentPreemptiveRate; 266 // fraction of data removed through acceleration (in Q14) 267 WebRtc_UWord16 currentAccelerateRate; 268 // clock-drift in parts-per-million (negative or positive) 269 int32_t clockDriftPPM; 270 // average packet waiting time in the jitter buffer (ms) 271 int meanWaitingTimeMs; 272 // median packet waiting time in the jitter buffer (ms) 273 int medianWaitingTimeMs; 274 // max packet waiting time in the jitter buffer (ms) 275 int maxWaitingTimeMs; 276 }; 277 278 typedef struct 279 { 280 int min; // minumum 281 int max; // maximum 282 int average; // average 283 } StatVal; 284 285 typedef struct // All levels are reported in dBm0 286 { 287 StatVal speech_rx; // long-term speech levels on receiving side 288 StatVal speech_tx; // long-term speech levels on transmitting side 289 StatVal noise_rx; // long-term noise/silence levels on receiving side 290 StatVal noise_tx; // long-term noise/silence levels on transmitting side 291 } LevelStatistics; 292 293 typedef struct // All levels are reported in dB 294 { 295 StatVal erl; // Echo Return Loss 296 StatVal erle; // Echo Return Loss Enhancement 297 StatVal rerl; // RERL = ERL + ERLE 298 // Echo suppression inside EC at the point just before its NLP 299 StatVal a_nlp; 300 } EchoStatistics; 301 302 enum TelephoneEventDetectionMethods 303 { 304 kInBand = 0, 305 kOutOfBand = 1, 306 kInAndOutOfBand = 2 307 }; 308 309 enum NsModes // type of Noise Suppression 310 { 311 kNsUnchanged = 0, // previously set mode 312 kNsDefault, // platform default 313 kNsConference, // conferencing default 314 kNsLowSuppression, // lowest suppression 315 kNsModerateSuppression, 316 kNsHighSuppression, 317 kNsVeryHighSuppression, // highest suppression 318 }; 319 320 enum AgcModes // type of Automatic Gain Control 321 { 322 kAgcUnchanged = 0, // previously set mode 323 kAgcDefault, // platform default 324 // adaptive mode for use when analog volume control exists (e.g. for 325 // PC softphone) 326 kAgcAdaptiveAnalog, 327 // scaling takes place in the digital domain (e.g. for conference servers 328 // and embedded devices) 329 kAgcAdaptiveDigital, 330 // can be used on embedded devices where the the capture signal is level 331 // is predictable 332 kAgcFixedDigital 333 }; 334 335 // EC modes 336 enum EcModes // type of Echo Control 337 { 338 kEcUnchanged = 0, // previously set mode 339 kEcDefault, // platform default 340 kEcConference, // conferencing default (aggressive AEC) 341 kEcAec, // Acoustic Echo Cancellation 342 kEcAecm, // AEC mobile 343 }; 344 345 // AECM modes 346 enum AecmModes // mode of AECM 347 { 348 kAecmQuietEarpieceOrHeadset = 0, 349 // Quiet earpiece or headset use 350 kAecmEarpiece, // most earpiece use 351 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use 352 kAecmSpeakerphone, // most speakerphone use (default) 353 kAecmLoudSpeakerphone // Loud speakerphone 354 }; 355 356 // AGC configuration 357 typedef struct 358 { 359 unsigned short targetLeveldBOv; 360 unsigned short digitalCompressionGaindB; 361 bool limiterEnable; 362 } AgcConfig; // AGC configuration parameters 363 364 enum StereoChannel 365 { 366 kStereoLeft = 0, 367 kStereoRight, 368 kStereoBoth 369 }; 370 371 // Audio device layers 372 enum AudioLayers 373 { 374 kAudioPlatformDefault = 0, 375 kAudioWindowsWave = 1, 376 kAudioWindowsCore = 2, 377 kAudioLinuxAlsa = 3, 378 kAudioLinuxPulse = 4 379 }; 380 381 enum NetEqModes // NetEQ playout configurations 382 { 383 // Optimized trade-off between low delay and jitter robustness for two-way 384 // communication. 385 kNetEqDefault = 0, 386 // Improved jitter robustness at the cost of increased delay. Can be 387 // used in one-way communication. 388 kNetEqStreaming = 1, 389 // Optimzed for decodability of fax signals rather than for perceived audio 390 // quality. 391 kNetEqFax = 2, 392 }; 393 394 enum NetEqBgnModes // NetEQ Background Noise (BGN) configurations 395 { 396 // BGN is always on and will be generated when the incoming RTP stream 397 // stops (default). 398 kBgnOn = 0, 399 // The BGN is faded to zero (complete silence) after a few seconds. 400 kBgnFade = 1, 401 // BGN is not used at all. Silence is produced after speech extrapolation 402 // has faded. 403 kBgnOff = 2, 404 }; 405 406 enum OnHoldModes // On Hold direction 407 { 408 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state. 409 kHoldSendOnly, // Put only sending in on-hold state. 410 kHoldPlayOnly // Put only playing in on-hold state. 411 }; 412 413 enum AmrMode 414 { 415 kRfc3267BwEfficient = 0, 416 kRfc3267OctetAligned = 1, 417 kRfc3267FileStorage = 2, 418 }; 419 420 // ================================================================== 421 // Video specific types 422 // ================================================================== 423 424 // Raw video types 425 enum RawVideoType 426 { 427 kVideoI420 = 0, 428 kVideoYV12 = 1, 429 kVideoYUY2 = 2, 430 kVideoUYVY = 3, 431 kVideoIYUV = 4, 432 kVideoARGB = 5, 433 kVideoRGB24 = 6, 434 kVideoRGB565 = 7, 435 kVideoARGB4444 = 8, 436 kVideoARGB1555 = 9, 437 kVideoMJPEG = 10, 438 kVideoNV12 = 11, 439 kVideoNV21 = 12, 440 kVideoBGRA = 13, 441 kVideoUnknown = 99 442 }; 443 444 // Video codec 445 enum { kConfigParameterSize = 128}; 446 enum { kPayloadNameSize = 32}; 447 enum { kMaxSimulcastStreams = 4}; 448 enum { kMaxTemporalStreams = 4}; 449 450 // H.263 specific 451 struct VideoCodecH263 452 { 453 char quality; 454 }; 455 456 // H.264 specific 457 enum H264Packetization 458 { 459 kH264SingleMode = 0, 460 kH264NonInterleavedMode = 1 461 }; 462 463 enum VideoCodecComplexity 464 { 465 kComplexityNormal = 0, 466 kComplexityHigh = 1, 467 kComplexityHigher = 2, 468 kComplexityMax = 3 469 }; 470 471 enum VideoCodecProfile 472 { 473 kProfileBase = 0x00, 474 kProfileMain = 0x01 475 }; 476 477 enum VP8ResilienceMode { 478 kResilienceOff, // The stream produced by the encoder requires a 479 // recovery frame (typically a key frame) to be 480 // decodable after a packet loss. 481 kResilientStream, // A stream produced by the encoder is resilient to 482 // packet losses, but packets within a frame subsequent 483 // to a loss can't be decoded. 484 kResilientFrames // Same as kResilientStream but with added resilience 485 // within a frame. 486 }; 487 488 struct VideoCodecH264 489 { 490 H264Packetization packetization; 491 VideoCodecComplexity complexity; 492 VideoCodecProfile profile; 493 char level; 494 char quality; 495 496 bool useFMO; 497 498 unsigned char configParameters[kConfigParameterSize]; 499 unsigned char configParametersSize; 500 }; 501 502 // VP8 specific 503 struct VideoCodecVP8 504 { 505 bool pictureLossIndicationOn; 506 bool feedbackModeOn; 507 VideoCodecComplexity complexity; 508 VP8ResilienceMode resilience; 509 unsigned char numberOfTemporalLayers; 510 }; 511 512 // MPEG-4 specific 513 struct VideoCodecMPEG4 514 { 515 unsigned char configParameters[kConfigParameterSize]; 516 unsigned char configParametersSize; 517 char level; 518 }; 519 520 // Unknown specific 521 struct VideoCodecGeneric 522 { 523 }; 524 525 // Video codec types 526 enum VideoCodecType 527 { 528 kVideoCodecH263, 529 kVideoCodecH264, 530 kVideoCodecVP8, 531 kVideoCodecMPEG4, 532 kVideoCodecI420, 533 kVideoCodecRED, 534 kVideoCodecULPFEC, 535 kVideoCodecUnknown 536 }; 537 538 union VideoCodecUnion 539 { 540 VideoCodecH263 H263; 541 VideoCodecH264 H264; 542 VideoCodecVP8 VP8; 543 VideoCodecMPEG4 MPEG4; 544 VideoCodecGeneric Generic; 545 }; 546 547 /* 548 * Simulcast is when the same stream is encoded multiple times with different 549 * settings such as resolution. 550 */ 551 struct SimulcastStream 552 { 553 unsigned short width; 554 unsigned short height; 555 unsigned char numberOfTemporalLayers; 556 unsigned int maxBitrate; 557 unsigned int qpMax; // minimum quality 558 }; 559 560 // Common video codec properties 561 struct VideoCodec 562 { 563 VideoCodecType codecType; 564 char plName[kPayloadNameSize]; 565 unsigned char plType; 566 567 unsigned short width; 568 unsigned short height; 569 570 unsigned int startBitrate; 571 unsigned int maxBitrate; 572 unsigned int minBitrate; 573 unsigned char maxFramerate; 574 575 VideoCodecUnion codecSpecific; 576 577 unsigned int qpMax; 578 unsigned char numberOfSimulcastStreams; 579 SimulcastStream simulcastStream[kMaxSimulcastStreams]; 580 }; 581 } // namespace webrtc 582 #endif // WEBRTC_COMMON_TYPES_H 583