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