Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / common_types.h
1 /*
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 "webrtc/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
36 #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
46 namespace webrtc {
47
48 class Config;
49
50 class InStream
51 {
52 public:
53     virtual int Read(void *buf,int len) = 0;
54     virtual int Rewind() {return -1;}
55     virtual ~InStream() {}
56 protected:
57     InStream() {}
58 };
59
60 class OutStream
61 {
62 public:
63     virtual bool Write(const void *buf,int len) = 0;
64     virtual int Rewind() {return -1;}
65     virtual ~OutStream() {}
66 protected:
67     OutStream() {}
68 };
69
70 enum TraceModule
71 {
72     kTraceUndefined              = 0,
73     // 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     kTraceRemoteBitrateEstimator = 0x0017,
94 };
95
96 enum TraceLevel
97 {
98     kTraceNone               = 0x0000,    // no trace
99     kTraceStateInfo          = 0x0001,
100     kTraceWarning            = 0x0002,
101     kTraceError              = 0x0004,
102     kTraceCritical           = 0x0008,
103     kTraceApiCall            = 0x0010,
104     kTraceDefault            = 0x00ff,
105
106     kTraceModuleCall         = 0x0020,
107     kTraceMemory             = 0x0100,   // memory info
108     kTraceTimer              = 0x0200,   // timing info
109     kTraceStream             = 0x0400,   // "continuous" stream of data
110
111     // used for debug purposes
112     kTraceDebug              = 0x0800,  // debug
113     kTraceInfo               = 0x1000,  // debug info
114
115     // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
116     kTraceTerseInfo          = 0x2000,
117
118     kTraceAll                = 0xffff
119 };
120
121 // External Trace API
122 class TraceCallback {
123  public:
124   virtual void Print(TraceLevel level, const char* message, int length) = 0;
125
126  protected:
127   virtual ~TraceCallback() {}
128   TraceCallback() {}
129 };
130
131 enum FileFormats
132 {
133     kFileFormatWavFile        = 1,
134     kFileFormatCompressedFile = 2,
135     kFileFormatAviFile        = 3,
136     kFileFormatPreencodedFile = 4,
137     kFileFormatPcm16kHzFile   = 7,
138     kFileFormatPcm8kHzFile    = 8,
139     kFileFormatPcm32kHzFile   = 9
140 };
141
142 enum ProcessingTypes
143 {
144     kPlaybackPerChannel = 0,
145     kPlaybackAllChannelsMixed,
146     kRecordingPerChannel,
147     kRecordingAllChannelsMixed,
148     kRecordingPreprocessing
149 };
150
151 enum FrameType
152 {
153     kFrameEmpty            = 0,
154     kAudioFrameSpeech      = 1,
155     kAudioFrameCN          = 2,
156     kVideoFrameKey         = 3,    // independent frame
157     kVideoFrameDelta       = 4,    // depends on the previus frame
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.
163 class Encryption
164 {
165 public:
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
220 protected:
221     virtual ~Encryption() {}
222     Encryption() {}
223 };
224
225 // External transport callback interface
226 class Transport
227 {
228 public:
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
232 protected:
233     virtual ~Transport() {}
234     Transport() {}
235 };
236
237 // Statistics for an RTCP channel
238 struct RtcpStatistics {
239   RtcpStatistics()
240     : fraction_lost(0),
241       cumulative_lost(0),
242       extended_max_sequence_number(0),
243       jitter(0) {}
244
245   uint8_t fraction_lost;
246   uint32_t cumulative_lost;
247   uint32_t extended_max_sequence_number;
248   uint32_t jitter;
249 };
250
251 // Callback, called whenever a new rtcp report block is transmitted.
252 class RtcpStatisticsCallback {
253  public:
254   virtual ~RtcpStatisticsCallback() {}
255
256   virtual void StatisticsUpdated(const RtcpStatistics& statistics,
257                                  uint32_t ssrc) = 0;
258 };
259
260 // Data usage statistics for a (rtp) stream
261 struct StreamDataCounters {
262   StreamDataCounters()
263    : bytes(0),
264      header_bytes(0),
265      padding_bytes(0),
266      packets(0),
267      retransmitted_packets(0),
268      fec_packets(0) {}
269
270   uint32_t bytes;  // Payload bytes, excluding RTP headers and padding.
271   uint32_t header_bytes;  // Number of bytes used by RTP headers.
272   uint32_t padding_bytes;  // Number of padding bytes.
273   uint32_t packets;  // Number of packets.
274   uint32_t retransmitted_packets;  // Number of retransmitted packets.
275   uint32_t fec_packets;  // Number of redundancy packets.
276 };
277
278 // Callback, called whenever byte/packet counts have been updated.
279 class StreamDataCountersCallback {
280  public:
281   virtual ~StreamDataCountersCallback() {}
282
283   virtual void DataCountersUpdated(const StreamDataCounters& counters,
284                                    uint32_t ssrc) = 0;
285 };
286
287 // Rate statistics for a stream
288 struct BitrateStatistics {
289   BitrateStatistics() : bitrate_bps(0), packet_rate(0), timestamp_ms(0) {}
290
291   uint32_t bitrate_bps;   // Bitrate in bits per second.
292   uint32_t packet_rate;   // Packet rate in packets per second.
293   uint64_t timestamp_ms;  // Ntp timestamp in ms at time of rate estimation.
294 };
295
296 // Callback, used to notify an observer whenever new rates have been estimated.
297 class BitrateStatisticsObserver {
298  public:
299   virtual ~BitrateStatisticsObserver() {}
300
301   virtual void Notify(const BitrateStatistics& stats, uint32_t ssrc) = 0;
302 };
303
304 // Callback, used to notify an observer whenever frame counts have been updated
305 class FrameCountObserver {
306  public:
307   virtual ~FrameCountObserver() {}
308   virtual void FrameCountUpdated(FrameType frame_type,
309                                  uint32_t frame_count,
310                                  const unsigned int ssrc) = 0;
311 };
312
313 // ==================================================================
314 // Voice specific types
315 // ==================================================================
316
317 // Each codec supported can be described by this structure.
318 struct CodecInst
319 {
320     int pltype;
321     char plname[RTP_PAYLOAD_NAME_SIZE];
322     int plfreq;
323     int pacsize;
324     int channels;
325     int rate;  // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
326 };
327
328 // RTP
329 enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
330
331 enum RTPDirections
332 {
333     kRtpIncoming = 0,
334     kRtpOutgoing
335 };
336
337 enum PayloadFrequencies
338 {
339     kFreq8000Hz = 8000,
340     kFreq16000Hz = 16000,
341     kFreq32000Hz = 32000
342 };
343
344 enum VadModes                 // degree of bandwidth reduction
345 {
346     kVadConventional = 0,      // lowest reduction
347     kVadAggressiveLow,
348     kVadAggressiveMid,
349     kVadAggressiveHigh         // highest reduction
350 };
351
352 struct NetworkStatistics           // NETEQ statistics
353 {
354     // current jitter buffer size in ms
355     uint16_t currentBufferSize;
356     // preferred (optimal) buffer size in ms
357     uint16_t preferredBufferSize;
358     // adding extra delay due to "peaky jitter"
359     bool jitterPeaksFound;
360     // loss rate (network + late) in percent (in Q14)
361     uint16_t currentPacketLossRate;
362     // late loss rate in percent (in Q14)
363     uint16_t currentDiscardRate;
364     // fraction (of original stream) of synthesized speech inserted through
365     // expansion (in Q14)
366     uint16_t currentExpandRate;
367     // fraction of synthesized speech inserted through pre-emptive expansion
368     // (in Q14)
369     uint16_t currentPreemptiveRate;
370     // fraction of data removed through acceleration (in Q14)
371     uint16_t currentAccelerateRate;
372     // clock-drift in parts-per-million (negative or positive)
373     int32_t clockDriftPPM;
374     // average packet waiting time in the jitter buffer (ms)
375     int meanWaitingTimeMs;
376     // median packet waiting time in the jitter buffer (ms)
377     int medianWaitingTimeMs;
378     // min packet waiting time in the jitter buffer (ms)
379     int minWaitingTimeMs;
380     // max packet waiting time in the jitter buffer (ms)
381     int maxWaitingTimeMs;
382     // added samples in off mode due to packet loss
383     int addedSamples;
384 };
385
386 // Statistics for calls to AudioCodingModule::PlayoutData10Ms().
387 struct AudioDecodingCallStats {
388   AudioDecodingCallStats()
389       : calls_to_silence_generator(0),
390         calls_to_neteq(0),
391         decoded_normal(0),
392         decoded_plc(0),
393         decoded_cng(0),
394         decoded_plc_cng(0) {}
395
396   int calls_to_silence_generator;  // Number of calls where silence generated,
397                                    // and NetEq was disengaged from decoding.
398   int calls_to_neteq;  // Number of calls to NetEq.
399   int decoded_normal;  // Number of calls where audio RTP packet decoded.
400   int decoded_plc;  // Number of calls resulted in PLC.
401   int decoded_cng;  // Number of calls where comfort noise generated due to DTX.
402   int decoded_plc_cng;  // Number of calls resulted where PLC faded to CNG.
403 };
404
405 typedef struct
406 {
407     int min;              // minumum
408     int max;              // maximum
409     int average;          // average
410 } StatVal;
411
412 typedef struct           // All levels are reported in dBm0
413 {
414     StatVal speech_rx;   // long-term speech levels on receiving side
415     StatVal speech_tx;   // long-term speech levels on transmitting side
416     StatVal noise_rx;    // long-term noise/silence levels on receiving side
417     StatVal noise_tx;    // long-term noise/silence levels on transmitting side
418 } LevelStatistics;
419
420 typedef struct        // All levels are reported in dB
421 {
422     StatVal erl;      // Echo Return Loss
423     StatVal erle;     // Echo Return Loss Enhancement
424     StatVal rerl;     // RERL = ERL + ERLE
425     // Echo suppression inside EC at the point just before its NLP
426     StatVal a_nlp;
427 } EchoStatistics;
428
429 enum NsModes    // type of Noise Suppression
430 {
431     kNsUnchanged = 0,   // previously set mode
432     kNsDefault,         // platform default
433     kNsConference,      // conferencing default
434     kNsLowSuppression,  // lowest suppression
435     kNsModerateSuppression,
436     kNsHighSuppression,
437     kNsVeryHighSuppression,     // highest suppression
438 };
439
440 enum AgcModes                  // type of Automatic Gain Control
441 {
442     kAgcUnchanged = 0,        // previously set mode
443     kAgcDefault,              // platform default
444     // adaptive mode for use when analog volume control exists (e.g. for
445     // PC softphone)
446     kAgcAdaptiveAnalog,
447     // scaling takes place in the digital domain (e.g. for conference servers
448     // and embedded devices)
449     kAgcAdaptiveDigital,
450     // can be used on embedded devices where the capture signal level
451     // is predictable
452     kAgcFixedDigital
453 };
454
455 // EC modes
456 enum EcModes                   // type of Echo Control
457 {
458     kEcUnchanged = 0,          // previously set mode
459     kEcDefault,                // platform default
460     kEcConference,             // conferencing default (aggressive AEC)
461     kEcAec,                    // Acoustic Echo Cancellation
462     kEcAecm,                   // AEC mobile
463 };
464
465 // AECM modes
466 enum AecmModes                 // mode of AECM
467 {
468     kAecmQuietEarpieceOrHeadset = 0,
469                                // Quiet earpiece or headset use
470     kAecmEarpiece,             // most earpiece use
471     kAecmLoudEarpiece,         // Loud earpiece or quiet speakerphone use
472     kAecmSpeakerphone,         // most speakerphone use (default)
473     kAecmLoudSpeakerphone      // Loud speakerphone
474 };
475
476 // AGC configuration
477 typedef struct
478 {
479     unsigned short targetLeveldBOv;
480     unsigned short digitalCompressionGaindB;
481     bool           limiterEnable;
482 } AgcConfig;                  // AGC configuration parameters
483
484 enum StereoChannel
485 {
486     kStereoLeft = 0,
487     kStereoRight,
488     kStereoBoth
489 };
490
491 // Audio device layers
492 enum AudioLayers
493 {
494     kAudioPlatformDefault = 0,
495     kAudioWindowsWave = 1,
496     kAudioWindowsCore = 2,
497     kAudioLinuxAlsa = 3,
498     kAudioLinuxPulse = 4
499 };
500
501 enum NetEqModes             // NetEQ playout configurations
502 {
503     // Optimized trade-off between low delay and jitter robustness for two-way
504     // communication.
505     kNetEqDefault = 0,
506     // Improved jitter robustness at the cost of increased delay. Can be
507     // used in one-way communication.
508     kNetEqStreaming = 1,
509     // Optimzed for decodability of fax signals rather than for perceived audio
510     // quality.
511     kNetEqFax = 2,
512     // Minimal buffer management. Inserts zeros for lost packets and during
513     // buffer increases.
514     kNetEqOff = 3,
515 };
516
517 enum OnHoldModes            // On Hold direction
518 {
519     kHoldSendAndPlay = 0,    // Put both sending and playing in on-hold state.
520     kHoldSendOnly,           // Put only sending in on-hold state.
521     kHoldPlayOnly            // Put only playing in on-hold state.
522 };
523
524 enum AmrMode
525 {
526     kRfc3267BwEfficient = 0,
527     kRfc3267OctetAligned = 1,
528     kRfc3267FileStorage = 2,
529 };
530
531 // ==================================================================
532 // Video specific types
533 // ==================================================================
534
535 // Raw video types
536 enum RawVideoType
537 {
538     kVideoI420     = 0,
539     kVideoYV12     = 1,
540     kVideoYUY2     = 2,
541     kVideoUYVY     = 3,
542     kVideoIYUV     = 4,
543     kVideoARGB     = 5,
544     kVideoRGB24    = 6,
545     kVideoRGB565   = 7,
546     kVideoARGB4444 = 8,
547     kVideoARGB1555 = 9,
548     kVideoMJPEG    = 10,
549     kVideoNV12     = 11,
550     kVideoNV21     = 12,
551     kVideoBGRA     = 13,
552     kVideoUnknown  = 99
553 };
554
555 // Video codec
556 enum { kConfigParameterSize = 128};
557 enum { kPayloadNameSize = 32};
558 enum { kMaxSimulcastStreams = 4};
559 enum { kMaxTemporalStreams = 4};
560
561 enum VideoCodecComplexity
562 {
563     kComplexityNormal = 0,
564     kComplexityHigh    = 1,
565     kComplexityHigher  = 2,
566     kComplexityMax     = 3
567 };
568
569 enum VideoCodecProfile
570 {
571     kProfileBase = 0x00,
572     kProfileMain = 0x01
573 };
574
575 enum VP8ResilienceMode {
576   kResilienceOff,    // The stream produced by the encoder requires a
577                      // recovery frame (typically a key frame) to be
578                      // decodable after a packet loss.
579   kResilientStream,  // A stream produced by the encoder is resilient to
580                      // packet losses, but packets within a frame subsequent
581                      // to a loss can't be decoded.
582   kResilientFrames   // Same as kResilientStream but with added resilience
583                      // within a frame.
584 };
585
586 // VP8 specific
587 struct VideoCodecVP8
588 {
589     bool                 pictureLossIndicationOn;
590     bool                 feedbackModeOn;
591     VideoCodecComplexity complexity;
592     VP8ResilienceMode    resilience;
593     unsigned char        numberOfTemporalLayers;
594     bool                 denoisingOn;
595     bool                 errorConcealmentOn;
596     bool                 automaticResizeOn;
597     bool                 frameDroppingOn;
598     int                  keyFrameInterval;
599 };
600
601 // Video codec types
602 enum VideoCodecType
603 {
604     kVideoCodecVP8,
605     kVideoCodecI420,
606     kVideoCodecRED,
607     kVideoCodecULPFEC,
608     kVideoCodecGeneric,
609     kVideoCodecUnknown
610 };
611
612 union VideoCodecUnion
613 {
614     VideoCodecVP8       VP8;
615 };
616
617
618 // Simulcast is when the same stream is encoded multiple times with different
619 // settings such as resolution.
620 struct SimulcastStream
621 {
622     unsigned short      width;
623     unsigned short      height;
624     unsigned char       numberOfTemporalLayers;
625     unsigned int        maxBitrate;  // kilobits/sec.
626     unsigned int        targetBitrate;  // kilobits/sec.
627     unsigned int        minBitrate;  // kilobits/sec.
628     unsigned int        qpMax; // minimum quality
629 };
630
631 enum VideoCodecMode {
632   kRealtimeVideo,
633   kScreensharing
634 };
635
636 // Common video codec properties
637 struct VideoCodec
638 {
639     VideoCodecType      codecType;
640     char                plName[kPayloadNameSize];
641     unsigned char       plType;
642
643     unsigned short      width;
644     unsigned short      height;
645
646     unsigned int        startBitrate;  // kilobits/sec.
647     unsigned int        maxBitrate;  // kilobits/sec.
648     unsigned int        minBitrate;  // kilobits/sec.
649     unsigned char       maxFramerate;
650
651     VideoCodecUnion     codecSpecific;
652
653     unsigned int        qpMax;
654     unsigned char       numberOfSimulcastStreams;
655     SimulcastStream     simulcastStream[kMaxSimulcastStreams];
656
657     VideoCodecMode      mode;
658
659     // When using an external encoder/decoder this allows to pass
660     // extra options without requiring webrtc to be aware of them.
661     Config*  extra_options;
662 };
663
664 // Bandwidth over-use detector options.  These are used to drive
665 // experimentation with bandwidth estimation parameters.
666 // See modules/remote_bitrate_estimator/overuse_detector.h
667 struct OverUseDetectorOptions {
668   OverUseDetectorOptions()
669       : initial_slope(8.0/512.0),
670         initial_offset(0),
671         initial_e(),
672         initial_process_noise(),
673         initial_avg_noise(0.0),
674         initial_var_noise(50),
675         initial_threshold(25.0) {
676     initial_e[0][0] = 100;
677     initial_e[1][1] = 1e-1;
678     initial_e[0][1] = initial_e[1][0] = 0;
679     initial_process_noise[0] = 1e-10;
680     initial_process_noise[1] = 1e-2;
681   }
682   double initial_slope;
683   double initial_offset;
684   double initial_e[2][2];
685   double initial_process_noise[2];
686   double initial_avg_noise;
687   double initial_var_noise;
688   double initial_threshold;
689 };
690
691 // This structure will have the information about when packet is actually
692 // received by socket.
693 struct PacketTime {
694   PacketTime() : timestamp(-1), max_error_us(-1) {}
695   PacketTime(int64_t timestamp, int64_t max_error_us)
696       : timestamp(timestamp), max_error_us(max_error_us) {
697   }
698
699   int64_t timestamp;    // Receive time after socket delivers the data.
700   int64_t max_error_us; // Earliest possible time the data could have arrived,
701                         // indicating the potential error in the |timestamp|
702                         // value,in case the system is busy.
703                         // For example, the time of the last select() call.
704                         // If unknown, this value will be set to zero.
705 };
706
707 }  // namespace webrtc
708
709 #endif  // WEBRTC_COMMON_TYPES_H_
710