2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_COMMON_TYPES_H_
12 #define WEBRTC_COMMON_TYPES_H_
14 #include "webrtc/typedefs.h"
17 // Disable "new behavior: elements of array will be default initialized"
18 // warning. Affects OverUseDetectorOptions.
19 #pragma warning(disable:4351)
23 #define WEBRTC_DLLEXPORT _declspec(dllexport)
25 #define WEBRTC_DLLEXPORT _declspec(dllimport)
27 #define WEBRTC_DLLEXPORT
34 #define RTP_PAYLOAD_NAME_SIZE 32
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)
42 #define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
43 #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
53 virtual int Read(void *buf,int len) = 0;
54 virtual int Rewind() {return -1;}
55 virtual ~InStream() {}
63 virtual bool Write(const void *buf,int len) = 0;
64 virtual int Rewind() {return -1;}
65 virtual ~OutStream() {}
73 // not a module, triggered from the engine code
75 // not a module, triggered from the engine code
77 // not a module, triggered from the utility code
78 kTraceUtility = 0x0003,
79 kTraceRtpRtcp = 0x0004,
80 kTraceTransport = 0x0005,
82 kTraceAudioCoding = 0x0007,
83 kTraceAudioMixerServer = 0x0008,
84 kTraceAudioMixerClient = 0x0009,
86 kTraceAudioProcessing = 0x000b,
87 kTraceVideoCoding = 0x0010,
88 kTraceVideoMixer = 0x0011,
89 kTraceAudioDevice = 0x0012,
90 kTraceVideoRenderer = 0x0014,
91 kTraceVideoCapture = 0x0015,
92 kTraceVideoPreocessing = 0x0016,
93 kTraceRemoteBitrateEstimator = 0x0017,
98 kTraceNone = 0x0000, // no trace
99 kTraceStateInfo = 0x0001,
100 kTraceWarning = 0x0002,
101 kTraceError = 0x0004,
102 kTraceCritical = 0x0008,
103 kTraceApiCall = 0x0010,
104 kTraceDefault = 0x00ff,
106 kTraceModuleCall = 0x0020,
107 kTraceMemory = 0x0100, // memory info
108 kTraceTimer = 0x0200, // timing info
109 kTraceStream = 0x0400, // "continuous" stream of data
111 // used for debug purposes
112 kTraceDebug = 0x0800, // debug
113 kTraceInfo = 0x1000, // debug info
115 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
116 kTraceTerseInfo = 0x2000,
121 // External Trace API
122 class TraceCallback {
124 virtual void Print(TraceLevel level, const char* message, int length) = 0;
127 virtual ~TraceCallback() {}
133 kFileFormatWavFile = 1,
134 kFileFormatCompressedFile = 2,
135 kFileFormatAviFile = 3,
136 kFileFormatPreencodedFile = 4,
137 kFileFormatPcm16kHzFile = 7,
138 kFileFormatPcm8kHzFile = 8,
139 kFileFormatPcm32kHzFile = 9
144 kPlaybackPerChannel = 0,
145 kPlaybackAllChannelsMixed,
146 kRecordingPerChannel,
147 kRecordingAllChannelsMixed,
148 kRecordingPreprocessing
154 kAudioFrameSpeech = 1,
156 kVideoFrameKey = 3, // independent frame
157 kVideoFrameDelta = 4, // depends on the previus frame
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.
166 // Encrypt the given data.
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(
179 unsigned char* in_data,
180 unsigned char* out_data,
184 // Decrypts the given data. This should reverse the effects of encrypt().
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(
197 unsigned char* in_data,
198 unsigned char* out_data,
202 // Encrypts a RTCP packet. Otherwise, this method has the same contract as
204 virtual void encrypt_rtcp(
206 unsigned char* in_data,
207 unsigned char* out_data,
211 // Decrypts a RTCP packet. Otherwise, this method has the same contract as
213 virtual void decrypt_rtcp(
215 unsigned char* in_data,
216 unsigned char* out_data,
221 virtual ~Encryption() {}
225 // External transport callback interface
229 virtual int SendPacket(int channel, const void *data, int len) = 0;
230 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0;
233 virtual ~Transport() {}
237 // Statistics for an RTCP channel
238 struct RtcpStatistics {
242 extended_max_sequence_number(0),
245 uint8_t fraction_lost;
246 uint32_t cumulative_lost;
247 uint32_t extended_max_sequence_number;
251 // Callback, called whenever a new rtcp report block is transmitted.
252 class RtcpStatisticsCallback {
254 virtual ~RtcpStatisticsCallback() {}
256 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
260 // Data usage statistics for a (rtp) stream
261 struct StreamDataCounters {
267 retransmitted_packets(0),
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.
278 // Callback, called whenever byte/packet counts have been updated.
279 class StreamDataCountersCallback {
281 virtual ~StreamDataCountersCallback() {}
283 virtual void DataCountersUpdated(const StreamDataCounters& counters,
287 // Rate statistics for a stream
288 struct BitrateStatistics {
289 BitrateStatistics() : bitrate_bps(0), packet_rate(0), timestamp_ms(0) {}
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.
296 // Callback, used to notify an observer whenever new rates have been estimated.
297 class BitrateStatisticsObserver {
299 virtual ~BitrateStatisticsObserver() {}
301 virtual void Notify(const BitrateStatistics& stats, uint32_t ssrc) = 0;
304 // Callback, used to notify an observer whenever frame counts have been updated
305 class FrameCountObserver {
307 virtual ~FrameCountObserver() {}
308 virtual void FrameCountUpdated(FrameType frame_type,
309 uint32_t frame_count,
310 const unsigned int ssrc) = 0;
313 // ==================================================================
314 // Voice specific types
315 // ==================================================================
317 // Each codec supported can be described by this structure.
321 char plname[RTP_PAYLOAD_NAME_SIZE];
325 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
329 enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
337 enum PayloadFrequencies
340 kFreq16000Hz = 16000,
344 enum VadModes // degree of bandwidth reduction
346 kVadConventional = 0, // lowest reduction
349 kVadAggressiveHigh // highest reduction
352 struct NetworkStatistics // NETEQ statistics
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
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
386 // Statistics for calls to AudioCodingModule::PlayoutData10Ms().
387 struct AudioDecodingCallStats {
388 AudioDecodingCallStats()
389 : calls_to_silence_generator(0),
394 decoded_plc_cng(0) {}
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.
409 int average; // average
412 typedef struct // All levels are reported in dBm0
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
420 typedef struct // All levels are reported in dB
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
429 enum NsModes // type of Noise Suppression
431 kNsUnchanged = 0, // previously set mode
432 kNsDefault, // platform default
433 kNsConference, // conferencing default
434 kNsLowSuppression, // lowest suppression
435 kNsModerateSuppression,
437 kNsVeryHighSuppression, // highest suppression
440 enum AgcModes // type of Automatic Gain Control
442 kAgcUnchanged = 0, // previously set mode
443 kAgcDefault, // platform default
444 // adaptive mode for use when analog volume control exists (e.g. for
447 // scaling takes place in the digital domain (e.g. for conference servers
448 // and embedded devices)
450 // can be used on embedded devices where the capture signal level
456 enum EcModes // type of Echo Control
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
466 enum AecmModes // mode of AECM
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
479 unsigned short targetLeveldBOv;
480 unsigned short digitalCompressionGaindB;
482 } AgcConfig; // AGC configuration parameters
491 // Audio device layers
494 kAudioPlatformDefault = 0,
495 kAudioWindowsWave = 1,
496 kAudioWindowsCore = 2,
501 enum NetEqModes // NetEQ playout configurations
503 // Optimized trade-off between low delay and jitter robustness for two-way
506 // Improved jitter robustness at the cost of increased delay. Can be
507 // used in one-way communication.
509 // Optimzed for decodability of fax signals rather than for perceived audio
512 // Minimal buffer management. Inserts zeros for lost packets and during
517 enum OnHoldModes // On Hold direction
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.
526 kRfc3267BwEfficient = 0,
527 kRfc3267OctetAligned = 1,
528 kRfc3267FileStorage = 2,
531 // ==================================================================
532 // Video specific types
533 // ==================================================================
556 enum { kConfigParameterSize = 128};
557 enum { kPayloadNameSize = 32};
558 enum { kMaxSimulcastStreams = 4};
559 enum { kMaxTemporalStreams = 4};
561 enum VideoCodecComplexity
563 kComplexityNormal = 0,
565 kComplexityHigher = 2,
569 enum VideoCodecProfile
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
589 bool pictureLossIndicationOn;
591 VideoCodecComplexity complexity;
592 VP8ResilienceMode resilience;
593 unsigned char numberOfTemporalLayers;
595 bool errorConcealmentOn;
596 bool automaticResizeOn;
597 bool frameDroppingOn;
598 int keyFrameInterval;
612 union VideoCodecUnion
618 // Simulcast is when the same stream is encoded multiple times with different
619 // settings such as resolution.
620 struct SimulcastStream
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
631 enum VideoCodecMode {
636 // Common video codec properties
639 VideoCodecType codecType;
640 char plName[kPayloadNameSize];
641 unsigned char plType;
643 unsigned short width;
644 unsigned short height;
646 unsigned int startBitrate; // kilobits/sec.
647 unsigned int maxBitrate; // kilobits/sec.
648 unsigned int minBitrate; // kilobits/sec.
649 unsigned char maxFramerate;
651 VideoCodecUnion codecSpecific;
654 unsigned char numberOfSimulcastStreams;
655 SimulcastStream simulcastStream[kMaxSimulcastStreams];
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;
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),
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;
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;
691 // This structure will have the information about when packet is actually
692 // received by socket.
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) {
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.
707 } // namespace webrtc
709 #endif // WEBRTC_COMMON_TYPES_H_