blob: 4ea58c7e1fbbb8c134de65e4827639079fec4fe1 [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
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000345enum NsModes // type of Noise Suppression
346{
347 kNsUnchanged = 0, // previously set mode
348 kNsDefault, // platform default
349 kNsConference, // conferencing default
350 kNsLowSuppression, // lowest suppression
351 kNsModerateSuppression,
352 kNsHighSuppression,
353 kNsVeryHighSuppression, // highest suppression
354};
355
356enum AgcModes // type of Automatic Gain Control
357{
358 kAgcUnchanged = 0, // previously set mode
359 kAgcDefault, // platform default
360 // adaptive mode for use when analog volume control exists (e.g. for
361 // PC softphone)
362 kAgcAdaptiveAnalog,
363 // scaling takes place in the digital domain (e.g. for conference servers
364 // and embedded devices)
365 kAgcAdaptiveDigital,
366 // can be used on embedded devices where the capture signal level
367 // is predictable
368 kAgcFixedDigital
369};
370
371// EC modes
372enum EcModes // type of Echo Control
373{
374 kEcUnchanged = 0, // previously set mode
375 kEcDefault, // platform default
376 kEcConference, // conferencing default (aggressive AEC)
377 kEcAec, // Acoustic Echo Cancellation
378 kEcAecm, // AEC mobile
379};
380
381// AECM modes
382enum AecmModes // mode of AECM
383{
384 kAecmQuietEarpieceOrHeadset = 0,
385 // Quiet earpiece or headset use
386 kAecmEarpiece, // most earpiece use
387 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
388 kAecmSpeakerphone, // most speakerphone use (default)
389 kAecmLoudSpeakerphone // Loud speakerphone
390};
391
392// AGC configuration
393typedef struct
394{
395 unsigned short targetLeveldBOv;
396 unsigned short digitalCompressionGaindB;
397 bool limiterEnable;
398} AgcConfig; // AGC configuration parameters
399
400enum StereoChannel
401{
402 kStereoLeft = 0,
403 kStereoRight,
404 kStereoBoth
405};
406
407// Audio device layers
408enum AudioLayers
409{
410 kAudioPlatformDefault = 0,
411 kAudioWindowsWave = 1,
412 kAudioWindowsCore = 2,
413 kAudioLinuxAlsa = 3,
414 kAudioLinuxPulse = 4
415};
416
417enum NetEqModes // NetEQ playout configurations
418{
419 // Optimized trade-off between low delay and jitter robustness for two-way
420 // communication.
421 kNetEqDefault = 0,
422 // Improved jitter robustness at the cost of increased delay. Can be
423 // used in one-way communication.
424 kNetEqStreaming = 1,
425 // Optimzed for decodability of fax signals rather than for perceived audio
426 // quality.
427 kNetEqFax = 2,
roosa@google.come68106f2012-12-12 21:59:14 +0000428 // Minimal buffer management. Inserts zeros for lost packets and during
429 // buffer increases.
430 kNetEqOff = 3,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000431};
432
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000433enum OnHoldModes // On Hold direction
434{
435 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
436 kHoldSendOnly, // Put only sending in on-hold state.
437 kHoldPlayOnly // Put only playing in on-hold state.
438};
439
440enum AmrMode
441{
442 kRfc3267BwEfficient = 0,
443 kRfc3267OctetAligned = 1,
444 kRfc3267FileStorage = 2,
445};
446
447// ==================================================================
448// Video specific types
449// ==================================================================
450
451// Raw video types
452enum RawVideoType
453{
454 kVideoI420 = 0,
455 kVideoYV12 = 1,
456 kVideoYUY2 = 2,
457 kVideoUYVY = 3,
458 kVideoIYUV = 4,
459 kVideoARGB = 5,
460 kVideoRGB24 = 6,
461 kVideoRGB565 = 7,
462 kVideoARGB4444 = 8,
463 kVideoARGB1555 = 9,
464 kVideoMJPEG = 10,
465 kVideoNV12 = 11,
466 kVideoNV21 = 12,
467 kVideoBGRA = 13,
468 kVideoUnknown = 99
469};
470
471// Video codec
472enum { kConfigParameterSize = 128};
473enum { kPayloadNameSize = 32};
474enum { kMaxSimulcastStreams = 4};
475enum { kMaxTemporalStreams = 4};
476
477enum VideoCodecComplexity
478{
479 kComplexityNormal = 0,
480 kComplexityHigh = 1,
481 kComplexityHigher = 2,
482 kComplexityMax = 3
483};
484
485enum VideoCodecProfile
486{
487 kProfileBase = 0x00,
488 kProfileMain = 0x01
489};
490
491enum VP8ResilienceMode {
492 kResilienceOff, // The stream produced by the encoder requires a
493 // recovery frame (typically a key frame) to be
494 // decodable after a packet loss.
495 kResilientStream, // A stream produced by the encoder is resilient to
496 // packet losses, but packets within a frame subsequent
497 // to a loss can't be decoded.
498 kResilientFrames // Same as kResilientStream but with added resilience
499 // within a frame.
500};
501
502// VP8 specific
503struct VideoCodecVP8
504{
505 bool pictureLossIndicationOn;
506 bool feedbackModeOn;
507 VideoCodecComplexity complexity;
508 VP8ResilienceMode resilience;
509 unsigned char numberOfTemporalLayers;
510 bool denoisingOn;
511 bool errorConcealmentOn;
512 bool automaticResizeOn;
513 bool frameDroppingOn;
mikhal@webrtc.org8d759af2013-01-31 16:37:13 +0000514 int keyFrameInterval;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000515};
516
517// Unknown specific
518struct VideoCodecGeneric
519{
520};
521
522// Video codec types
523enum VideoCodecType
524{
525 kVideoCodecVP8,
526 kVideoCodecI420,
527 kVideoCodecRED,
528 kVideoCodecULPFEC,
pbos@webrtc.orga2e91242013-03-18 16:39:03 +0000529 kVideoCodecGeneric,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000530 kVideoCodecUnknown
531};
532
533union VideoCodecUnion
534{
535 VideoCodecVP8 VP8;
536 VideoCodecGeneric Generic;
537};
538
539
540// Simulcast is when the same stream is encoded multiple times with different
541// settings such as resolution.
542struct SimulcastStream
543{
544 unsigned short width;
545 unsigned short height;
546 unsigned char numberOfTemporalLayers;
547 unsigned int maxBitrate;
548 unsigned int qpMax; // minimum quality
549};
550
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000551enum VideoCodecMode {
552 kRealtimeVideo,
553 kScreensharing
554};
555
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000556// Common video codec properties
557struct VideoCodec
558{
559 VideoCodecType codecType;
560 char plName[kPayloadNameSize];
561 unsigned char plType;
562
563 unsigned short width;
564 unsigned short height;
565
566 unsigned int startBitrate;
567 unsigned int maxBitrate;
568 unsigned int minBitrate;
569 unsigned char maxFramerate;
570
571 VideoCodecUnion codecSpecific;
572
573 unsigned int qpMax;
574 unsigned char numberOfSimulcastStreams;
575 SimulcastStream simulcastStream[kMaxSimulcastStreams];
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000576
577 VideoCodecMode mode;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000578};
579
580// Bandwidth over-use detector options. These are used to drive
581// experimentation with bandwidth estimation parameters.
582// See modules/remote_bitrate_estimator/overuse_detector.h
583struct OverUseDetectorOptions {
584 OverUseDetectorOptions()
585 : initial_slope(8.0/512.0),
586 initial_offset(0),
587 initial_e(),
588 initial_process_noise(),
589 initial_avg_noise(0.0),
590 initial_var_noise(50),
591 initial_threshold(25.0) {
592 initial_e[0][0] = 100;
593 initial_e[1][1] = 1e-1;
594 initial_e[0][1] = initial_e[1][0] = 0;
595 initial_process_noise[0] = 1e-10;
596 initial_process_noise[1] = 1e-2;
597 }
598 double initial_slope;
599 double initial_offset;
600 double initial_e[2][2];
601 double initial_process_noise[2];
602 double initial_avg_noise;
603 double initial_var_noise;
604 double initial_threshold;
605};
606} // namespace webrtc
607#endif // WEBRTC_COMMON_TYPES_H