blob: fc1979c1051fcdf06fe91f7a9ddf7006eecaa186 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
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.orgd898c012012-11-14 19:07:5460 kTraceUndefined = 0,
andrew@webrtc.orgb015cbe2012-10-22 18:19:2361 // 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
102 kTraceAll = 0xffff
103};
104
105// External Trace API
andrew@webrtc.orgd75680a2012-11-15 05:33:25106class TraceCallback {
107 public:
108 virtual void Print(TraceLevel level, const char* message, int length) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23109
andrew@webrtc.orgd75680a2012-11-15 05:33:25110 protected:
111 virtual ~TraceCallback() {}
112 TraceCallback() {}
113};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23114
115enum FileFormats
116{
117 kFileFormatWavFile = 1,
118 kFileFormatCompressedFile = 2,
119 kFileFormatAviFile = 3,
120 kFileFormatPreencodedFile = 4,
121 kFileFormatPcm16kHzFile = 7,
122 kFileFormatPcm8kHzFile = 8,
123 kFileFormatPcm32kHzFile = 9
124};
125
126
127enum ProcessingTypes
128{
129 kPlaybackPerChannel = 0,
130 kPlaybackAllChannelsMixed,
131 kRecordingPerChannel,
132 kRecordingAllChannelsMixed,
133 kRecordingPreprocessing
134};
135
136// Encryption enums
137enum CipherTypes
138{
139 kCipherNull = 0,
140 kCipherAes128CounterMode = 1
141};
142
143enum AuthenticationTypes
144{
145 kAuthNull = 0,
146 kAuthHmacSha1 = 3
147};
148
149enum SecurityLevels
150{
151 kNoProtection = 0,
152 kEncryption = 1,
153 kAuthentication = 2,
154 kEncryptionAndAuthentication = 3
155};
156
157// Interface for encrypting and decrypting regular data and rtp/rtcp packets.
158// Implement this interface if you wish to provide an encryption scheme to
159// the voice or video engines.
160class Encryption
161{
162public:
163 // Encrypt the given data.
164 //
165 // Args:
166 // channel: The channel to encrypt data for.
167 // in_data: The data to encrypt. This data is bytes_in bytes long.
168 // out_data: The buffer to write the encrypted data to. You may write more
169 // bytes of encrypted 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 encrypt(
175 int channel,
176 unsigned char* in_data,
177 unsigned char* out_data,
178 int bytes_in,
179 int* bytes_out) = 0;
180
181 // Decrypts the given data. This should reverse the effects of encrypt().
182 //
183 // Args:
184 // channel_no: The channel to decrypt data for.
185 // in_data: The data to decrypt. This data is bytes_in bytes long.
186 // out_data: The buffer to write the decrypted data to. You may write more
187 // bytes of decrypted data than what you got as input, up to a maximum
188 // of webrtc::kViEMaxMtu if you are encrypting in the video engine, or
189 // webrtc::kVoiceEngineMaxIpPacketSizeBytes for the voice engine.
190 // bytes_in: The number of bytes in the input buffer.
191 // bytes_out: The number of bytes written in out_data.
192 virtual void decrypt(
193 int channel,
194 unsigned char* in_data,
195 unsigned char* out_data,
196 int bytes_in,
197 int* bytes_out) = 0;
198
199 // Encrypts a RTCP packet. Otherwise, this method has the same contract as
200 // encrypt().
201 virtual void encrypt_rtcp(
202 int channel,
203 unsigned char* in_data,
204 unsigned char* out_data,
205 int bytes_in,
206 int* bytes_out) = 0;
207
208 // Decrypts a RTCP packet. Otherwise, this method has the same contract as
209 // decrypt().
210 virtual void decrypt_rtcp(
211 int channel,
212 unsigned char* in_data,
213 unsigned char* out_data,
214 int bytes_in,
215 int* bytes_out) = 0;
216
217protected:
218 virtual ~Encryption() {}
219 Encryption() {}
220};
221
222// External transport callback interface
223class Transport
224{
225public:
226 virtual int SendPacket(int channel, const void *data, int len) = 0;
227 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0;
228
229protected:
230 virtual ~Transport() {}
231 Transport() {}
232};
233
234// ==================================================================
235// Voice specific types
236// ==================================================================
237
238// Each codec supported can be described by this structure.
239struct CodecInst
240{
241 int pltype;
242 char plname[RTP_PAYLOAD_NAME_SIZE];
243 int plfreq;
244 int pacsize;
245 int channels;
246 int rate;
247};
248
249enum FrameType
250{
251 kFrameEmpty = 0,
252 kAudioFrameSpeech = 1,
253 kAudioFrameCN = 2,
254 kVideoFrameKey = 3, // independent frame
255 kVideoFrameDelta = 4, // depends on the previus frame
256 kVideoFrameGolden = 5, // depends on a old known previus frame
257 kVideoFrameAltRef = 6
258};
259
260// RTP
261enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
262
263enum RTPDirections
264{
265 kRtpIncoming = 0,
266 kRtpOutgoing
267};
268
269enum PayloadFrequencies
270{
271 kFreq8000Hz = 8000,
272 kFreq16000Hz = 16000,
273 kFreq32000Hz = 32000
274};
275
276enum VadModes // degree of bandwidth reduction
277{
278 kVadConventional = 0, // lowest reduction
279 kVadAggressiveLow,
280 kVadAggressiveMid,
281 kVadAggressiveHigh // highest reduction
282};
283
284struct NetworkStatistics // NETEQ statistics
285{
286 // current jitter buffer size in ms
287 WebRtc_UWord16 currentBufferSize;
288 // preferred (optimal) buffer size in ms
289 WebRtc_UWord16 preferredBufferSize;
290 // adding extra delay due to "peaky jitter"
291 bool jitterPeaksFound;
292 // loss rate (network + late) in percent (in Q14)
293 WebRtc_UWord16 currentPacketLossRate;
294 // late loss rate in percent (in Q14)
295 WebRtc_UWord16 currentDiscardRate;
296 // fraction (of original stream) of synthesized speech inserted through
297 // expansion (in Q14)
298 WebRtc_UWord16 currentExpandRate;
299 // fraction of synthesized speech inserted through pre-emptive expansion
300 // (in Q14)
301 WebRtc_UWord16 currentPreemptiveRate;
302 // fraction of data removed through acceleration (in Q14)
303 WebRtc_UWord16 currentAccelerateRate;
304 // clock-drift in parts-per-million (negative or positive)
305 int32_t clockDriftPPM;
306 // average packet waiting time in the jitter buffer (ms)
307 int meanWaitingTimeMs;
308 // median packet waiting time in the jitter buffer (ms)
309 int medianWaitingTimeMs;
310 // min packet waiting time in the jitter buffer (ms)
311 int minWaitingTimeMs;
312 // max packet waiting time in the jitter buffer (ms)
313 int maxWaitingTimeMs;
314};
315
316typedef struct
317{
318 int min; // minumum
319 int max; // maximum
320 int average; // average
321} StatVal;
322
323typedef struct // All levels are reported in dBm0
324{
325 StatVal speech_rx; // long-term speech levels on receiving side
326 StatVal speech_tx; // long-term speech levels on transmitting side
327 StatVal noise_rx; // long-term noise/silence levels on receiving side
328 StatVal noise_tx; // long-term noise/silence levels on transmitting side
329} LevelStatistics;
330
331typedef struct // All levels are reported in dB
332{
333 StatVal erl; // Echo Return Loss
334 StatVal erle; // Echo Return Loss Enhancement
335 StatVal rerl; // RERL = ERL + ERLE
336 // Echo suppression inside EC at the point just before its NLP
337 StatVal a_nlp;
338} EchoStatistics;
339
340enum TelephoneEventDetectionMethods
341{
342 kInBand = 0,
343 kOutOfBand = 1,
344 kInAndOutOfBand = 2
345};
346
347enum NsModes // type of Noise Suppression
348{
349 kNsUnchanged = 0, // previously set mode
350 kNsDefault, // platform default
351 kNsConference, // conferencing default
352 kNsLowSuppression, // lowest suppression
353 kNsModerateSuppression,
354 kNsHighSuppression,
355 kNsVeryHighSuppression, // highest suppression
356};
357
358enum AgcModes // type of Automatic Gain Control
359{
360 kAgcUnchanged = 0, // previously set mode
361 kAgcDefault, // platform default
362 // adaptive mode for use when analog volume control exists (e.g. for
363 // PC softphone)
364 kAgcAdaptiveAnalog,
365 // scaling takes place in the digital domain (e.g. for conference servers
366 // and embedded devices)
367 kAgcAdaptiveDigital,
368 // can be used on embedded devices where the capture signal level
369 // is predictable
370 kAgcFixedDigital
371};
372
373// EC modes
374enum EcModes // type of Echo Control
375{
376 kEcUnchanged = 0, // previously set mode
377 kEcDefault, // platform default
378 kEcConference, // conferencing default (aggressive AEC)
379 kEcAec, // Acoustic Echo Cancellation
380 kEcAecm, // AEC mobile
381};
382
383// AECM modes
384enum AecmModes // mode of AECM
385{
386 kAecmQuietEarpieceOrHeadset = 0,
387 // Quiet earpiece or headset use
388 kAecmEarpiece, // most earpiece use
389 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
390 kAecmSpeakerphone, // most speakerphone use (default)
391 kAecmLoudSpeakerphone // Loud speakerphone
392};
393
394// AGC configuration
395typedef struct
396{
397 unsigned short targetLeveldBOv;
398 unsigned short digitalCompressionGaindB;
399 bool limiterEnable;
400} AgcConfig; // AGC configuration parameters
401
402enum StereoChannel
403{
404 kStereoLeft = 0,
405 kStereoRight,
406 kStereoBoth
407};
408
409// Audio device layers
410enum AudioLayers
411{
412 kAudioPlatformDefault = 0,
413 kAudioWindowsWave = 1,
414 kAudioWindowsCore = 2,
415 kAudioLinuxAlsa = 3,
416 kAudioLinuxPulse = 4
417};
418
419enum NetEqModes // NetEQ playout configurations
420{
421 // Optimized trade-off between low delay and jitter robustness for two-way
422 // communication.
423 kNetEqDefault = 0,
424 // Improved jitter robustness at the cost of increased delay. Can be
425 // used in one-way communication.
426 kNetEqStreaming = 1,
427 // Optimzed for decodability of fax signals rather than for perceived audio
428 // quality.
429 kNetEqFax = 2,
430};
431
432enum NetEqBgnModes // NetEQ Background Noise (BGN) configurations
433{
434 // BGN is always on and will be generated when the incoming RTP stream
435 // stops (default).
436 kBgnOn = 0,
437 // The BGN is faded to zero (complete silence) after a few seconds.
438 kBgnFade = 1,
439 // BGN is not used at all. Silence is produced after speech extrapolation
440 // has faded.
441 kBgnOff = 2,
442};
443
444enum OnHoldModes // On Hold direction
445{
446 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
447 kHoldSendOnly, // Put only sending in on-hold state.
448 kHoldPlayOnly // Put only playing in on-hold state.
449};
450
451enum AmrMode
452{
453 kRfc3267BwEfficient = 0,
454 kRfc3267OctetAligned = 1,
455 kRfc3267FileStorage = 2,
456};
457
458// ==================================================================
459// Video specific types
460// ==================================================================
461
462// Raw video types
463enum RawVideoType
464{
465 kVideoI420 = 0,
466 kVideoYV12 = 1,
467 kVideoYUY2 = 2,
468 kVideoUYVY = 3,
469 kVideoIYUV = 4,
470 kVideoARGB = 5,
471 kVideoRGB24 = 6,
472 kVideoRGB565 = 7,
473 kVideoARGB4444 = 8,
474 kVideoARGB1555 = 9,
475 kVideoMJPEG = 10,
476 kVideoNV12 = 11,
477 kVideoNV21 = 12,
478 kVideoBGRA = 13,
479 kVideoUnknown = 99
480};
481
482// Video codec
483enum { kConfigParameterSize = 128};
484enum { kPayloadNameSize = 32};
485enum { kMaxSimulcastStreams = 4};
486enum { kMaxTemporalStreams = 4};
487
488enum VideoCodecComplexity
489{
490 kComplexityNormal = 0,
491 kComplexityHigh = 1,
492 kComplexityHigher = 2,
493 kComplexityMax = 3
494};
495
496enum VideoCodecProfile
497{
498 kProfileBase = 0x00,
499 kProfileMain = 0x01
500};
501
502enum VP8ResilienceMode {
503 kResilienceOff, // The stream produced by the encoder requires a
504 // recovery frame (typically a key frame) to be
505 // decodable after a packet loss.
506 kResilientStream, // A stream produced by the encoder is resilient to
507 // packet losses, but packets within a frame subsequent
508 // to a loss can't be decoded.
509 kResilientFrames // Same as kResilientStream but with added resilience
510 // within a frame.
511};
512
513// VP8 specific
514struct VideoCodecVP8
515{
516 bool pictureLossIndicationOn;
517 bool feedbackModeOn;
518 VideoCodecComplexity complexity;
519 VP8ResilienceMode resilience;
520 unsigned char numberOfTemporalLayers;
521 bool denoisingOn;
522 bool errorConcealmentOn;
523 bool automaticResizeOn;
524 bool frameDroppingOn;
525};
526
527// Unknown specific
528struct VideoCodecGeneric
529{
530};
531
532// Video codec types
533enum VideoCodecType
534{
535 kVideoCodecVP8,
536 kVideoCodecI420,
537 kVideoCodecRED,
538 kVideoCodecULPFEC,
539 kVideoCodecUnknown
540};
541
542union VideoCodecUnion
543{
544 VideoCodecVP8 VP8;
545 VideoCodecGeneric Generic;
546};
547
548
549// Simulcast is when the same stream is encoded multiple times with different
550// settings such as resolution.
551struct 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
561struct 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
582// Bandwidth over-use detector options. These are used to drive
583// experimentation with bandwidth estimation parameters.
584// See modules/remote_bitrate_estimator/overuse_detector.h
585struct OverUseDetectorOptions {
586 OverUseDetectorOptions()
587 : initial_slope(8.0/512.0),
588 initial_offset(0),
589 initial_e(),
590 initial_process_noise(),
591 initial_avg_noise(0.0),
592 initial_var_noise(50),
593 initial_threshold(25.0) {
594 initial_e[0][0] = 100;
595 initial_e[1][1] = 1e-1;
596 initial_e[0][1] = initial_e[1][0] = 0;
597 initial_process_noise[0] = 1e-10;
598 initial_process_noise[1] = 1e-2;
599 }
600 double initial_slope;
601 double initial_offset;
602 double initial_e[2][2];
603 double initial_process_noise[2];
604 double initial_avg_noise;
605 double initial_var_noise;
606 double initial_threshold;
607};
608} // namespace webrtc
609#endif // WEBRTC_COMMON_TYPES_H