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