blob: 58ac57103f3a5f74cbd43e05681a1d02fc576326 [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
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#ifndef WEBRTC_COMMON_TYPES_H
12#define WEBRTC_COMMON_TYPES_H
13
14#include "typedefs.h"
15
16#if defined(_MSC_VER)
17// Disable "new behavior: elements of array will be default initialized"
18// warning. Affects OverUseDetectorOptions.
19#pragma warning(disable:4351)
20#endif
21
22#ifdef WEBRTC_EXPORT
23#define WEBRTC_DLLEXPORT _declspec(dllexport)
24#elif WEBRTC_DLL
25#define WEBRTC_DLLEXPORT _declspec(dllimport)
26#else
27#define WEBRTC_DLLEXPORT
28#endif
29
30#ifndef NULL
31#define NULL 0
32#endif
33
34#define RTP_PAYLOAD_NAME_SIZE 32
35
36namespace webrtc {
37
38class InStream
39{
40public:
41 virtual int Read(void *buf,int len) = 0;
42 virtual int Rewind() {return -1;}
43 virtual ~InStream() {}
44protected:
45 InStream() {}
46};
47
48class OutStream
49{
50public:
51 virtual bool Write(const void *buf,int len) = 0;
52 virtual int Rewind() {return -1;}
53 virtual ~OutStream() {}
54protected:
55 OutStream() {}
56};
57
58enum TraceModule
59{
andrew@webrtc.org75c70432012-11-14 19:07:54 +000060 kTraceUndefined = 0,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000061 // not a module, triggered from the engine code
62 kTraceVoice = 0x0001,
63 // not a module, triggered from the engine code
64 kTraceVideo = 0x0002,
65 // not a module, triggered from the utility code
66 kTraceUtility = 0x0003,
67 kTraceRtpRtcp = 0x0004,
68 kTraceTransport = 0x0005,
69 kTraceSrtp = 0x0006,
70 kTraceAudioCoding = 0x0007,
71 kTraceAudioMixerServer = 0x0008,
72 kTraceAudioMixerClient = 0x0009,
73 kTraceFile = 0x000a,
74 kTraceAudioProcessing = 0x000b,
75 kTraceVideoCoding = 0x0010,
76 kTraceVideoMixer = 0x0011,
77 kTraceAudioDevice = 0x0012,
78 kTraceVideoRenderer = 0x0014,
79 kTraceVideoCapture = 0x0015,
80 kTraceVideoPreocessing = 0x0016
81};
82
83enum TraceLevel
84{
85 kTraceNone = 0x0000, // no trace
86 kTraceStateInfo = 0x0001,
87 kTraceWarning = 0x0002,
88 kTraceError = 0x0004,
89 kTraceCritical = 0x0008,
90 kTraceApiCall = 0x0010,
91 kTraceDefault = 0x00ff,
92
93 kTraceModuleCall = 0x0020,
94 kTraceMemory = 0x0100, // memory info
95 kTraceTimer = 0x0200, // timing info
96 kTraceStream = 0x0400, // "continuous" stream of data
97
98 // used for debug purposes
99 kTraceDebug = 0x0800, // debug
100 kTraceInfo = 0x1000, // debug info
101
andrew@webrtc.org10e0b282012-11-20 07:34:45 +0000102 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
103 kTraceTerseInfo = 0x2000,
104
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000105 kTraceAll = 0xffff
106};
107
108// External Trace API
andrew@webrtc.org4c8c3072012-11-15 05:33:25 +0000109class TraceCallback {
110 public:
111 virtual void Print(TraceLevel level, const char* message, int length) = 0;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000112
andrew@webrtc.org4c8c3072012-11-15 05:33:25 +0000113 protected:
114 virtual ~TraceCallback() {}
115 TraceCallback() {}
116};
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000117
118enum FileFormats
119{
120 kFileFormatWavFile = 1,
121 kFileFormatCompressedFile = 2,
122 kFileFormatAviFile = 3,
123 kFileFormatPreencodedFile = 4,
124 kFileFormatPcm16kHzFile = 7,
125 kFileFormatPcm8kHzFile = 8,
126 kFileFormatPcm32kHzFile = 9
127};
128
129
130enum ProcessingTypes
131{
132 kPlaybackPerChannel = 0,
133 kPlaybackAllChannelsMixed,
134 kRecordingPerChannel,
135 kRecordingAllChannelsMixed,
136 kRecordingPreprocessing
137};
138
139// Encryption enums
140enum CipherTypes
141{
142 kCipherNull = 0,
143 kCipherAes128CounterMode = 1
144};
145
146enum AuthenticationTypes
147{
148 kAuthNull = 0,
149 kAuthHmacSha1 = 3
150};
151
152enum SecurityLevels
153{
154 kNoProtection = 0,
155 kEncryption = 1,
156 kAuthentication = 2,
157 kEncryptionAndAuthentication = 3
158};
159
160// Interface for encrypting and decrypting regular data and rtp/rtcp packets.
161// Implement this interface if you wish to provide an encryption scheme to
162// the voice or video engines.
163class Encryption
164{
165public:
166 // Encrypt the given data.
167 //
168 // Args:
169 // channel: The channel to encrypt data for.
170 // in_data: The data to encrypt. This data is bytes_in bytes long.
171 // out_data: The buffer to write the encrypted data to. You may write more
172 // bytes of encrypted data than what you got as input, up to a maximum
173 // of webrtc::kViEMaxMtu if you are encrypting in the video engine, or
174 // webrtc::kVoiceEngineMaxIpPacketSizeBytes for the voice engine.
175 // bytes_in: The number of bytes in the input buffer.
176 // bytes_out: The number of bytes written in out_data.
177 virtual void encrypt(
178 int channel,
179 unsigned char* in_data,
180 unsigned char* out_data,
181 int bytes_in,
182 int* bytes_out) = 0;
183
184 // Decrypts the given data. This should reverse the effects of encrypt().
185 //
186 // Args:
187 // channel_no: The channel to decrypt data for.
188 // in_data: The data to decrypt. This data is bytes_in bytes long.
189 // out_data: The buffer to write the decrypted data to. You may write more
190 // bytes of decrypted data than what you got as input, up to a maximum
191 // of webrtc::kViEMaxMtu if you are encrypting in the video engine, or
192 // webrtc::kVoiceEngineMaxIpPacketSizeBytes for the voice engine.
193 // bytes_in: The number of bytes in the input buffer.
194 // bytes_out: The number of bytes written in out_data.
195 virtual void decrypt(
196 int channel,
197 unsigned char* in_data,
198 unsigned char* out_data,
199 int bytes_in,
200 int* bytes_out) = 0;
201
202 // Encrypts a RTCP packet. Otherwise, this method has the same contract as
203 // encrypt().
204 virtual void encrypt_rtcp(
205 int channel,
206 unsigned char* in_data,
207 unsigned char* out_data,
208 int bytes_in,
209 int* bytes_out) = 0;
210
211 // Decrypts a RTCP packet. Otherwise, this method has the same contract as
212 // decrypt().
213 virtual void decrypt_rtcp(
214 int channel,
215 unsigned char* in_data,
216 unsigned char* out_data,
217 int bytes_in,
218 int* bytes_out) = 0;
219
220protected:
221 virtual ~Encryption() {}
222 Encryption() {}
223};
224
225// External transport callback interface
226class Transport
227{
228public:
229 virtual int SendPacket(int channel, const void *data, int len) = 0;
230 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0;
231
232protected:
233 virtual ~Transport() {}
234 Transport() {}
235};
236
237// ==================================================================
238// Voice specific types
239// ==================================================================
240
241// Each codec supported can be described by this structure.
242struct CodecInst
243{
244 int pltype;
245 char plname[RTP_PAYLOAD_NAME_SIZE];
246 int plfreq;
247 int pacsize;
248 int channels;
249 int rate;
250};
251
252enum FrameType
253{
254 kFrameEmpty = 0,
255 kAudioFrameSpeech = 1,
256 kAudioFrameCN = 2,
257 kVideoFrameKey = 3, // independent frame
258 kVideoFrameDelta = 4, // depends on the previus frame
259 kVideoFrameGolden = 5, // depends on a old known previus frame
260 kVideoFrameAltRef = 6
261};
262
263// RTP
264enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
265
266enum RTPDirections
267{
268 kRtpIncoming = 0,
269 kRtpOutgoing
270};
271
272enum PayloadFrequencies
273{
274 kFreq8000Hz = 8000,
275 kFreq16000Hz = 16000,
276 kFreq32000Hz = 32000
277};
278
279enum VadModes // degree of bandwidth reduction
280{
281 kVadConventional = 0, // lowest reduction
282 kVadAggressiveLow,
283 kVadAggressiveMid,
284 kVadAggressiveHigh // highest reduction
285};
286
287struct NetworkStatistics // NETEQ statistics
288{
289 // current jitter buffer size in ms
290 WebRtc_UWord16 currentBufferSize;
291 // preferred (optimal) buffer size in ms
292 WebRtc_UWord16 preferredBufferSize;
293 // adding extra delay due to "peaky jitter"
294 bool jitterPeaksFound;
295 // loss rate (network + late) in percent (in Q14)
296 WebRtc_UWord16 currentPacketLossRate;
297 // late loss rate in percent (in Q14)
298 WebRtc_UWord16 currentDiscardRate;
299 // fraction (of original stream) of synthesized speech inserted through
300 // expansion (in Q14)
301 WebRtc_UWord16 currentExpandRate;
302 // fraction of synthesized speech inserted through pre-emptive expansion
303 // (in Q14)
304 WebRtc_UWord16 currentPreemptiveRate;
305 // fraction of data removed through acceleration (in Q14)
306 WebRtc_UWord16 currentAccelerateRate;
307 // clock-drift in parts-per-million (negative or positive)
308 int32_t clockDriftPPM;
309 // average packet waiting time in the jitter buffer (ms)
310 int meanWaitingTimeMs;
311 // median packet waiting time in the jitter buffer (ms)
312 int medianWaitingTimeMs;
313 // min packet waiting time in the jitter buffer (ms)
314 int minWaitingTimeMs;
315 // max packet waiting time in the jitter buffer (ms)
316 int maxWaitingTimeMs;
roosa@google.comd0a96082012-12-14 00:06:18 +0000317 // added samples in off mode due to packet loss
318 int addedSamples;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000319};
320
321typedef struct
322{
323 int min; // minumum
324 int max; // maximum
325 int average; // average
326} StatVal;
327
328typedef struct // All levels are reported in dBm0
329{
330 StatVal speech_rx; // long-term speech levels on receiving side
331 StatVal speech_tx; // long-term speech levels on transmitting side
332 StatVal noise_rx; // long-term noise/silence levels on receiving side
333 StatVal noise_tx; // long-term noise/silence levels on transmitting side
334} LevelStatistics;
335
336typedef struct // All levels are reported in dB
337{
338 StatVal erl; // Echo Return Loss
339 StatVal erle; // Echo Return Loss Enhancement
340 StatVal rerl; // RERL = ERL + ERLE
341 // Echo suppression inside EC at the point just before its NLP
342 StatVal a_nlp;
343} EchoStatistics;
344
345enum TelephoneEventDetectionMethods
346{
347 kInBand = 0,
348 kOutOfBand = 1,
349 kInAndOutOfBand = 2
350};
351
352enum NsModes // type of Noise Suppression
353{
354 kNsUnchanged = 0, // previously set mode
355 kNsDefault, // platform default
356 kNsConference, // conferencing default
357 kNsLowSuppression, // lowest suppression
358 kNsModerateSuppression,
359 kNsHighSuppression,
360 kNsVeryHighSuppression, // highest suppression
361};
362
363enum AgcModes // type of Automatic Gain Control
364{
365 kAgcUnchanged = 0, // previously set mode
366 kAgcDefault, // platform default
367 // adaptive mode for use when analog volume control exists (e.g. for
368 // PC softphone)
369 kAgcAdaptiveAnalog,
370 // scaling takes place in the digital domain (e.g. for conference servers
371 // and embedded devices)
372 kAgcAdaptiveDigital,
373 // can be used on embedded devices where the capture signal level
374 // is predictable
375 kAgcFixedDigital
376};
377
378// EC modes
379enum EcModes // type of Echo Control
380{
381 kEcUnchanged = 0, // previously set mode
382 kEcDefault, // platform default
383 kEcConference, // conferencing default (aggressive AEC)
384 kEcAec, // Acoustic Echo Cancellation
385 kEcAecm, // AEC mobile
386};
387
388// AECM modes
389enum AecmModes // mode of AECM
390{
391 kAecmQuietEarpieceOrHeadset = 0,
392 // Quiet earpiece or headset use
393 kAecmEarpiece, // most earpiece use
394 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
395 kAecmSpeakerphone, // most speakerphone use (default)
396 kAecmLoudSpeakerphone // Loud speakerphone
397};
398
399// AGC configuration
400typedef struct
401{
402 unsigned short targetLeveldBOv;
403 unsigned short digitalCompressionGaindB;
404 bool limiterEnable;
405} AgcConfig; // AGC configuration parameters
406
407enum StereoChannel
408{
409 kStereoLeft = 0,
410 kStereoRight,
411 kStereoBoth
412};
413
414// Audio device layers
415enum AudioLayers
416{
417 kAudioPlatformDefault = 0,
418 kAudioWindowsWave = 1,
419 kAudioWindowsCore = 2,
420 kAudioLinuxAlsa = 3,
421 kAudioLinuxPulse = 4
422};
423
424enum NetEqModes // NetEQ playout configurations
425{
426 // Optimized trade-off between low delay and jitter robustness for two-way
427 // communication.
428 kNetEqDefault = 0,
429 // Improved jitter robustness at the cost of increased delay. Can be
430 // used in one-way communication.
431 kNetEqStreaming = 1,
432 // Optimzed for decodability of fax signals rather than for perceived audio
433 // quality.
434 kNetEqFax = 2,
roosa@google.come68106f2012-12-12 21:59:14 +0000435 // Minimal buffer management. Inserts zeros for lost packets and during
436 // buffer increases.
437 kNetEqOff = 3,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000438};
439
440enum NetEqBgnModes // NetEQ Background Noise (BGN) configurations
441{
442 // BGN is always on and will be generated when the incoming RTP stream
443 // stops (default).
444 kBgnOn = 0,
445 // The BGN is faded to zero (complete silence) after a few seconds.
446 kBgnFade = 1,
447 // BGN is not used at all. Silence is produced after speech extrapolation
448 // has faded.
449 kBgnOff = 2,
450};
451
452enum OnHoldModes // On Hold direction
453{
454 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
455 kHoldSendOnly, // Put only sending in on-hold state.
456 kHoldPlayOnly // Put only playing in on-hold state.
457};
458
459enum AmrMode
460{
461 kRfc3267BwEfficient = 0,
462 kRfc3267OctetAligned = 1,
463 kRfc3267FileStorage = 2,
464};
465
466// ==================================================================
467// Video specific types
468// ==================================================================
469
470// Raw video types
471enum RawVideoType
472{
473 kVideoI420 = 0,
474 kVideoYV12 = 1,
475 kVideoYUY2 = 2,
476 kVideoUYVY = 3,
477 kVideoIYUV = 4,
478 kVideoARGB = 5,
479 kVideoRGB24 = 6,
480 kVideoRGB565 = 7,
481 kVideoARGB4444 = 8,
482 kVideoARGB1555 = 9,
483 kVideoMJPEG = 10,
484 kVideoNV12 = 11,
485 kVideoNV21 = 12,
486 kVideoBGRA = 13,
487 kVideoUnknown = 99
488};
489
490// Video codec
491enum { kConfigParameterSize = 128};
492enum { kPayloadNameSize = 32};
493enum { kMaxSimulcastStreams = 4};
494enum { kMaxTemporalStreams = 4};
495
496enum VideoCodecComplexity
497{
498 kComplexityNormal = 0,
499 kComplexityHigh = 1,
500 kComplexityHigher = 2,
501 kComplexityMax = 3
502};
503
504enum VideoCodecProfile
505{
506 kProfileBase = 0x00,
507 kProfileMain = 0x01
508};
509
510enum VP8ResilienceMode {
511 kResilienceOff, // The stream produced by the encoder requires a
512 // recovery frame (typically a key frame) to be
513 // decodable after a packet loss.
514 kResilientStream, // A stream produced by the encoder is resilient to
515 // packet losses, but packets within a frame subsequent
516 // to a loss can't be decoded.
517 kResilientFrames // Same as kResilientStream but with added resilience
518 // within a frame.
519};
520
521// VP8 specific
522struct VideoCodecVP8
523{
524 bool pictureLossIndicationOn;
525 bool feedbackModeOn;
526 VideoCodecComplexity complexity;
527 VP8ResilienceMode resilience;
528 unsigned char numberOfTemporalLayers;
529 bool denoisingOn;
530 bool errorConcealmentOn;
531 bool automaticResizeOn;
532 bool frameDroppingOn;
mikhal@webrtc.org8d759af2013-01-31 16:37:13 +0000533 int keyFrameInterval;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000534};
535
536// Unknown specific
537struct VideoCodecGeneric
538{
539};
540
541// Video codec types
542enum VideoCodecType
543{
544 kVideoCodecVP8,
545 kVideoCodecI420,
546 kVideoCodecRED,
547 kVideoCodecULPFEC,
548 kVideoCodecUnknown
549};
550
551union VideoCodecUnion
552{
553 VideoCodecVP8 VP8;
554 VideoCodecGeneric Generic;
555};
556
557
558// Simulcast is when the same stream is encoded multiple times with different
559// settings such as resolution.
560struct SimulcastStream
561{
562 unsigned short width;
563 unsigned short height;
564 unsigned char numberOfTemporalLayers;
565 unsigned int maxBitrate;
566 unsigned int qpMax; // minimum quality
567};
568
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000569enum VideoCodecMode {
570 kRealtimeVideo,
571 kScreensharing
572};
573
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000574// Common video codec properties
575struct VideoCodec
576{
577 VideoCodecType codecType;
578 char plName[kPayloadNameSize];
579 unsigned char plType;
580
581 unsigned short width;
582 unsigned short height;
583
584 unsigned int startBitrate;
585 unsigned int maxBitrate;
586 unsigned int minBitrate;
587 unsigned char maxFramerate;
588
589 VideoCodecUnion codecSpecific;
590
591 unsigned int qpMax;
592 unsigned char numberOfSimulcastStreams;
593 SimulcastStream simulcastStream[kMaxSimulcastStreams];
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000594
595 VideoCodecMode mode;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000596};
597
598// Bandwidth over-use detector options. These are used to drive
599// experimentation with bandwidth estimation parameters.
600// See modules/remote_bitrate_estimator/overuse_detector.h
601struct OverUseDetectorOptions {
602 OverUseDetectorOptions()
603 : initial_slope(8.0/512.0),
604 initial_offset(0),
605 initial_e(),
606 initial_process_noise(),
607 initial_avg_noise(0.0),
608 initial_var_noise(50),
609 initial_threshold(25.0) {
610 initial_e[0][0] = 100;
611 initial_e[1][1] = 1e-1;
612 initial_e[0][1] = initial_e[1][0] = 0;
613 initial_process_noise[0] = 1e-10;
614 initial_process_noise[1] = 1e-2;
615 }
616 double initial_slope;
617 double initial_offset;
618 double initial_e[2][2];
619 double initial_process_noise[2];
620 double initial_avg_noise;
621 double initial_var_noise;
622 double initial_threshold;
623};
624} // namespace webrtc
625#endif // WEBRTC_COMMON_TYPES_H