blob: 5001da2974dece4304f29197ebd7b6d89d7f3fdf [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
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000139// Interface for encrypting and decrypting regular data and rtp/rtcp packets.
140// Implement this interface if you wish to provide an encryption scheme to
141// the voice or video engines.
142class Encryption
143{
144public:
145 // Encrypt the given data.
146 //
147 // Args:
148 // channel: The channel to encrypt data for.
149 // in_data: The data to encrypt. This data is bytes_in bytes long.
150 // out_data: The buffer to write the encrypted data to. You may write more
151 // bytes of encrypted data than what you got as input, up to a maximum
152 // of webrtc::kViEMaxMtu if you are encrypting in the video engine, or
153 // webrtc::kVoiceEngineMaxIpPacketSizeBytes for the voice engine.
154 // bytes_in: The number of bytes in the input buffer.
155 // bytes_out: The number of bytes written in out_data.
156 virtual void encrypt(
157 int channel,
158 unsigned char* in_data,
159 unsigned char* out_data,
160 int bytes_in,
161 int* bytes_out) = 0;
162
163 // Decrypts the given data. This should reverse the effects of encrypt().
164 //
165 // Args:
166 // channel_no: The channel to decrypt data for.
167 // in_data: The data to decrypt. This data is bytes_in bytes long.
168 // out_data: The buffer to write the decrypted data to. You may write more
169 // bytes of decrypted data than what you got as input, up to a maximum
170 // of webrtc::kViEMaxMtu if you are encrypting in the video engine, or
171 // webrtc::kVoiceEngineMaxIpPacketSizeBytes for the voice engine.
172 // bytes_in: The number of bytes in the input buffer.
173 // bytes_out: The number of bytes written in out_data.
174 virtual void decrypt(
175 int channel,
176 unsigned char* in_data,
177 unsigned char* out_data,
178 int bytes_in,
179 int* bytes_out) = 0;
180
181 // Encrypts a RTCP packet. Otherwise, this method has the same contract as
182 // encrypt().
183 virtual void encrypt_rtcp(
184 int channel,
185 unsigned char* in_data,
186 unsigned char* out_data,
187 int bytes_in,
188 int* bytes_out) = 0;
189
190 // Decrypts a RTCP packet. Otherwise, this method has the same contract as
191 // decrypt().
192 virtual void decrypt_rtcp(
193 int channel,
194 unsigned char* in_data,
195 unsigned char* out_data,
196 int bytes_in,
197 int* bytes_out) = 0;
198
199protected:
200 virtual ~Encryption() {}
201 Encryption() {}
202};
203
204// External transport callback interface
205class Transport
206{
207public:
208 virtual int SendPacket(int channel, const void *data, int len) = 0;
209 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0;
210
211protected:
212 virtual ~Transport() {}
213 Transport() {}
214};
215
216// ==================================================================
217// Voice specific types
218// ==================================================================
219
220// Each codec supported can be described by this structure.
221struct CodecInst
222{
223 int pltype;
224 char plname[RTP_PAYLOAD_NAME_SIZE];
225 int plfreq;
226 int pacsize;
227 int channels;
228 int rate;
229};
230
231enum FrameType
232{
233 kFrameEmpty = 0,
234 kAudioFrameSpeech = 1,
235 kAudioFrameCN = 2,
236 kVideoFrameKey = 3, // independent frame
237 kVideoFrameDelta = 4, // depends on the previus frame
238 kVideoFrameGolden = 5, // depends on a old known previus frame
239 kVideoFrameAltRef = 6
240};
241
242// RTP
243enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
244
245enum RTPDirections
246{
247 kRtpIncoming = 0,
248 kRtpOutgoing
249};
250
251enum PayloadFrequencies
252{
253 kFreq8000Hz = 8000,
254 kFreq16000Hz = 16000,
255 kFreq32000Hz = 32000
256};
257
258enum VadModes // degree of bandwidth reduction
259{
260 kVadConventional = 0, // lowest reduction
261 kVadAggressiveLow,
262 kVadAggressiveMid,
263 kVadAggressiveHigh // highest reduction
264};
265
266struct NetworkStatistics // NETEQ statistics
267{
268 // current jitter buffer size in ms
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000269 uint16_t currentBufferSize;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000270 // preferred (optimal) buffer size in ms
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000271 uint16_t preferredBufferSize;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000272 // adding extra delay due to "peaky jitter"
273 bool jitterPeaksFound;
274 // loss rate (network + late) in percent (in Q14)
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000275 uint16_t currentPacketLossRate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000276 // late loss rate in percent (in Q14)
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000277 uint16_t currentDiscardRate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000278 // fraction (of original stream) of synthesized speech inserted through
279 // expansion (in Q14)
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000280 uint16_t currentExpandRate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000281 // fraction of synthesized speech inserted through pre-emptive expansion
282 // (in Q14)
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000283 uint16_t currentPreemptiveRate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000284 // fraction of data removed through acceleration (in Q14)
pbos@webrtc.orgc22830f2013-05-03 12:02:11 +0000285 uint16_t currentAccelerateRate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000286 // clock-drift in parts-per-million (negative or positive)
287 int32_t clockDriftPPM;
288 // average packet waiting time in the jitter buffer (ms)
289 int meanWaitingTimeMs;
290 // median packet waiting time in the jitter buffer (ms)
291 int medianWaitingTimeMs;
292 // min packet waiting time in the jitter buffer (ms)
293 int minWaitingTimeMs;
294 // max packet waiting time in the jitter buffer (ms)
295 int maxWaitingTimeMs;
roosa@google.comd0a96082012-12-14 00:06:18 +0000296 // added samples in off mode due to packet loss
297 int addedSamples;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000298};
299
300typedef struct
301{
302 int min; // minumum
303 int max; // maximum
304 int average; // average
305} StatVal;
306
307typedef struct // All levels are reported in dBm0
308{
309 StatVal speech_rx; // long-term speech levels on receiving side
310 StatVal speech_tx; // long-term speech levels on transmitting side
311 StatVal noise_rx; // long-term noise/silence levels on receiving side
312 StatVal noise_tx; // long-term noise/silence levels on transmitting side
313} LevelStatistics;
314
315typedef struct // All levels are reported in dB
316{
317 StatVal erl; // Echo Return Loss
318 StatVal erle; // Echo Return Loss Enhancement
319 StatVal rerl; // RERL = ERL + ERLE
320 // Echo suppression inside EC at the point just before its NLP
321 StatVal a_nlp;
322} EchoStatistics;
323
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000324enum NsModes // type of Noise Suppression
325{
326 kNsUnchanged = 0, // previously set mode
327 kNsDefault, // platform default
328 kNsConference, // conferencing default
329 kNsLowSuppression, // lowest suppression
330 kNsModerateSuppression,
331 kNsHighSuppression,
332 kNsVeryHighSuppression, // highest suppression
333};
334
335enum AgcModes // type of Automatic Gain Control
336{
337 kAgcUnchanged = 0, // previously set mode
338 kAgcDefault, // platform default
339 // adaptive mode for use when analog volume control exists (e.g. for
340 // PC softphone)
341 kAgcAdaptiveAnalog,
342 // scaling takes place in the digital domain (e.g. for conference servers
343 // and embedded devices)
344 kAgcAdaptiveDigital,
345 // can be used on embedded devices where the capture signal level
346 // is predictable
347 kAgcFixedDigital
348};
349
350// EC modes
351enum EcModes // type of Echo Control
352{
353 kEcUnchanged = 0, // previously set mode
354 kEcDefault, // platform default
355 kEcConference, // conferencing default (aggressive AEC)
356 kEcAec, // Acoustic Echo Cancellation
357 kEcAecm, // AEC mobile
358};
359
360// AECM modes
361enum AecmModes // mode of AECM
362{
363 kAecmQuietEarpieceOrHeadset = 0,
364 // Quiet earpiece or headset use
365 kAecmEarpiece, // most earpiece use
366 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
367 kAecmSpeakerphone, // most speakerphone use (default)
368 kAecmLoudSpeakerphone // Loud speakerphone
369};
370
371// AGC configuration
372typedef struct
373{
374 unsigned short targetLeveldBOv;
375 unsigned short digitalCompressionGaindB;
376 bool limiterEnable;
377} AgcConfig; // AGC configuration parameters
378
379enum StereoChannel
380{
381 kStereoLeft = 0,
382 kStereoRight,
383 kStereoBoth
384};
385
386// Audio device layers
387enum AudioLayers
388{
389 kAudioPlatformDefault = 0,
390 kAudioWindowsWave = 1,
391 kAudioWindowsCore = 2,
392 kAudioLinuxAlsa = 3,
393 kAudioLinuxPulse = 4
394};
395
396enum NetEqModes // NetEQ playout configurations
397{
398 // Optimized trade-off between low delay and jitter robustness for two-way
399 // communication.
400 kNetEqDefault = 0,
401 // Improved jitter robustness at the cost of increased delay. Can be
402 // used in one-way communication.
403 kNetEqStreaming = 1,
404 // Optimzed for decodability of fax signals rather than for perceived audio
405 // quality.
406 kNetEqFax = 2,
roosa@google.come68106f2012-12-12 21:59:14 +0000407 // Minimal buffer management. Inserts zeros for lost packets and during
408 // buffer increases.
409 kNetEqOff = 3,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000410};
411
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000412enum OnHoldModes // On Hold direction
413{
414 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
415 kHoldSendOnly, // Put only sending in on-hold state.
416 kHoldPlayOnly // Put only playing in on-hold state.
417};
418
419enum AmrMode
420{
421 kRfc3267BwEfficient = 0,
422 kRfc3267OctetAligned = 1,
423 kRfc3267FileStorage = 2,
424};
425
426// ==================================================================
427// Video specific types
428// ==================================================================
429
430// Raw video types
431enum RawVideoType
432{
433 kVideoI420 = 0,
434 kVideoYV12 = 1,
435 kVideoYUY2 = 2,
436 kVideoUYVY = 3,
437 kVideoIYUV = 4,
438 kVideoARGB = 5,
439 kVideoRGB24 = 6,
440 kVideoRGB565 = 7,
441 kVideoARGB4444 = 8,
442 kVideoARGB1555 = 9,
443 kVideoMJPEG = 10,
444 kVideoNV12 = 11,
445 kVideoNV21 = 12,
446 kVideoBGRA = 13,
447 kVideoUnknown = 99
448};
449
450// Video codec
451enum { kConfigParameterSize = 128};
452enum { kPayloadNameSize = 32};
453enum { kMaxSimulcastStreams = 4};
454enum { kMaxTemporalStreams = 4};
455
456enum VideoCodecComplexity
457{
458 kComplexityNormal = 0,
459 kComplexityHigh = 1,
460 kComplexityHigher = 2,
461 kComplexityMax = 3
462};
463
464enum VideoCodecProfile
465{
466 kProfileBase = 0x00,
467 kProfileMain = 0x01
468};
469
470enum VP8ResilienceMode {
471 kResilienceOff, // The stream produced by the encoder requires a
472 // recovery frame (typically a key frame) to be
473 // decodable after a packet loss.
474 kResilientStream, // A stream produced by the encoder is resilient to
475 // packet losses, but packets within a frame subsequent
476 // to a loss can't be decoded.
477 kResilientFrames // Same as kResilientStream but with added resilience
478 // within a frame.
479};
480
481// VP8 specific
482struct VideoCodecVP8
483{
484 bool pictureLossIndicationOn;
485 bool feedbackModeOn;
486 VideoCodecComplexity complexity;
487 VP8ResilienceMode resilience;
488 unsigned char numberOfTemporalLayers;
489 bool denoisingOn;
490 bool errorConcealmentOn;
491 bool automaticResizeOn;
492 bool frameDroppingOn;
mikhal@webrtc.org8d759af2013-01-31 16:37:13 +0000493 int keyFrameInterval;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000494};
495
496// Unknown specific
497struct VideoCodecGeneric
498{
499};
500
501// Video codec types
502enum VideoCodecType
503{
504 kVideoCodecVP8,
505 kVideoCodecI420,
506 kVideoCodecRED,
507 kVideoCodecULPFEC,
pbos@webrtc.orga2e91242013-03-18 16:39:03 +0000508 kVideoCodecGeneric,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000509 kVideoCodecUnknown
510};
511
512union VideoCodecUnion
513{
514 VideoCodecVP8 VP8;
515 VideoCodecGeneric Generic;
516};
517
518
519// Simulcast is when the same stream is encoded multiple times with different
520// settings such as resolution.
521struct SimulcastStream
522{
523 unsigned short width;
524 unsigned short height;
525 unsigned char numberOfTemporalLayers;
526 unsigned int maxBitrate;
marpan@webrtc.org90fa4a12013-03-22 17:13:08 +0000527 unsigned int targetBitrate;
528 unsigned int minBitrate;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000529 unsigned int qpMax; // minimum quality
530};
531
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000532enum VideoCodecMode {
533 kRealtimeVideo,
534 kScreensharing
535};
536
andresp@webrtc.org1efb11c2013-04-23 22:50:53 +0000537// When using an external encoder/decoder one may need to specify extra
538// options. This struct definition is left for the external implementation.
539// TODO(andresp): Support for multiple external encoder/decoders.
540struct ExtraCodecOptions;
541
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000542// Common video codec properties
543struct VideoCodec
544{
545 VideoCodecType codecType;
546 char plName[kPayloadNameSize];
547 unsigned char plType;
548
549 unsigned short width;
550 unsigned short height;
551
552 unsigned int startBitrate;
553 unsigned int maxBitrate;
554 unsigned int minBitrate;
555 unsigned char maxFramerate;
556
557 VideoCodecUnion codecSpecific;
558
559 unsigned int qpMax;
560 unsigned char numberOfSimulcastStreams;
561 SimulcastStream simulcastStream[kMaxSimulcastStreams];
stefan@webrtc.org85e2e0e2013-02-18 14:40:18 +0000562
563 VideoCodecMode mode;
andresp@webrtc.org1efb11c2013-04-23 22:50:53 +0000564 ExtraCodecOptions* extra_options;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000565};
566
567// Bandwidth over-use detector options. These are used to drive
568// experimentation with bandwidth estimation parameters.
569// See modules/remote_bitrate_estimator/overuse_detector.h
570struct OverUseDetectorOptions {
571 OverUseDetectorOptions()
572 : initial_slope(8.0/512.0),
573 initial_offset(0),
574 initial_e(),
575 initial_process_noise(),
576 initial_avg_noise(0.0),
577 initial_var_noise(50),
578 initial_threshold(25.0) {
579 initial_e[0][0] = 100;
580 initial_e[1][1] = 1e-1;
581 initial_e[0][1] = initial_e[1][0] = 0;
582 initial_process_noise[0] = 1e-10;
583 initial_process_noise[1] = 1e-2;
584 }
585 double initial_slope;
586 double initial_offset;
587 double initial_e[2][2];
588 double initial_process_noise[2];
589 double initial_avg_noise;
590 double initial_var_noise;
591 double initial_threshold;
592};
593} // namespace webrtc
594#endif // WEBRTC_COMMON_TYPES_H