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_
18 #include "webrtc/typedefs.h"
21 // Disable "new behavior: elements of array will be default initialized"
22 // warning. Affects OverUseDetectorOptions.
23 #pragma warning(disable:4351)
27 #define WEBRTC_DLLEXPORT _declspec(dllexport)
29 #define WEBRTC_DLLEXPORT _declspec(dllimport)
31 #define WEBRTC_DLLEXPORT
38 #define RTP_PAYLOAD_NAME_SIZE 32
40 #if defined(WEBRTC_WIN) || defined(WIN32)
41 // Compares two strings without regard to case.
42 #define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
43 // Compares characters of two strings without regard to case.
44 #define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
46 #define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
47 #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
57 virtual int Read(void *buf,int len) = 0;
58 virtual int Rewind() {return -1;}
59 virtual ~InStream() {}
67 virtual bool Write(const void *buf,int len) = 0;
68 virtual int Rewind() {return -1;}
69 virtual ~OutStream() {}
77 // not a module, triggered from the engine code
79 // not a module, triggered from the engine code
81 // not a module, triggered from the utility code
82 kTraceUtility = 0x0003,
83 kTraceRtpRtcp = 0x0004,
84 kTraceTransport = 0x0005,
86 kTraceAudioCoding = 0x0007,
87 kTraceAudioMixerServer = 0x0008,
88 kTraceAudioMixerClient = 0x0009,
90 kTraceAudioProcessing = 0x000b,
91 kTraceVideoCoding = 0x0010,
92 kTraceVideoMixer = 0x0011,
93 kTraceAudioDevice = 0x0012,
94 kTraceVideoRenderer = 0x0014,
95 kTraceVideoCapture = 0x0015,
96 kTraceRemoteBitrateEstimator = 0x0017,
101 kTraceNone = 0x0000, // no trace
102 kTraceStateInfo = 0x0001,
103 kTraceWarning = 0x0002,
104 kTraceError = 0x0004,
105 kTraceCritical = 0x0008,
106 kTraceApiCall = 0x0010,
107 kTraceDefault = 0x00ff,
109 kTraceModuleCall = 0x0020,
110 kTraceMemory = 0x0100, // memory info
111 kTraceTimer = 0x0200, // timing info
112 kTraceStream = 0x0400, // "continuous" stream of data
114 // used for debug purposes
115 kTraceDebug = 0x0800, // debug
116 kTraceInfo = 0x1000, // debug info
118 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
119 kTraceTerseInfo = 0x2000,
124 // External Trace API
125 class TraceCallback {
127 virtual void Print(TraceLevel level, const char* message, int length) = 0;
130 virtual ~TraceCallback() {}
136 kFileFormatWavFile = 1,
137 kFileFormatCompressedFile = 2,
138 kFileFormatAviFile = 3,
139 kFileFormatPreencodedFile = 4,
140 kFileFormatPcm16kHzFile = 7,
141 kFileFormatPcm8kHzFile = 8,
142 kFileFormatPcm32kHzFile = 9
147 kPlaybackPerChannel = 0,
148 kPlaybackAllChannelsMixed,
149 kRecordingPerChannel,
150 kRecordingAllChannelsMixed,
151 kRecordingPreprocessing
157 kAudioFrameSpeech = 1,
159 kVideoFrameKey = 3, // independent frame
160 kVideoFrameDelta = 4, // depends on the previus frame
163 // External transport callback interface
167 virtual int SendPacket(int channel, const void *data, int len) = 0;
168 virtual int SendRTCPPacket(int channel, const void *data, int len) = 0;
171 virtual ~Transport() {}
175 // Statistics for an RTCP channel
176 struct RtcpStatistics {
180 extended_max_sequence_number(0),
183 uint8_t fraction_lost;
184 uint32_t cumulative_lost;
185 uint32_t extended_max_sequence_number;
189 // Callback, called whenever a new rtcp report block is transmitted.
190 class RtcpStatisticsCallback {
192 virtual ~RtcpStatisticsCallback() {}
194 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
198 // Statistics for RTCP packet types.
199 struct RtcpPacketTypeCounter {
200 RtcpPacketTypeCounter()
205 void Add(const RtcpPacketTypeCounter& other) {
206 nack_packets += other.nack_packets;
207 fir_packets += other.fir_packets;
208 pli_packets += other.pli_packets;
211 uint32_t nack_packets;
212 uint32_t fir_packets;
213 uint32_t pli_packets;
216 // Data usage statistics for a (rtp) stream
217 struct StreamDataCounters {
223 retransmitted_packets(0),
226 uint32_t bytes; // Payload bytes, excluding RTP headers and padding.
227 uint32_t header_bytes; // Number of bytes used by RTP headers.
228 uint32_t padding_bytes; // Number of padding bytes.
229 uint32_t packets; // Number of packets.
230 uint32_t retransmitted_packets; // Number of retransmitted packets.
231 uint32_t fec_packets; // Number of redundancy packets.
234 // Callback, called whenever byte/packet counts have been updated.
235 class StreamDataCountersCallback {
237 virtual ~StreamDataCountersCallback() {}
239 virtual void DataCountersUpdated(const StreamDataCounters& counters,
243 // Rate statistics for a stream
244 struct BitrateStatistics {
245 BitrateStatistics() : bitrate_bps(0), packet_rate(0), timestamp_ms(0) {}
247 uint32_t bitrate_bps; // Bitrate in bits per second.
248 uint32_t packet_rate; // Packet rate in packets per second.
249 uint64_t timestamp_ms; // Ntp timestamp in ms at time of rate estimation.
252 // Callback, used to notify an observer whenever new rates have been estimated.
253 class BitrateStatisticsObserver {
255 virtual ~BitrateStatisticsObserver() {}
257 virtual void Notify(const BitrateStatistics& stats, uint32_t ssrc) = 0;
260 // Callback, used to notify an observer whenever frame counts have been updated
261 class FrameCountObserver {
263 virtual ~FrameCountObserver() {}
264 virtual void FrameCountUpdated(FrameType frame_type,
265 uint32_t frame_count,
266 const unsigned int ssrc) = 0;
269 // ==================================================================
270 // Voice specific types
271 // ==================================================================
273 // Each codec supported can be described by this structure.
276 char plname[RTP_PAYLOAD_NAME_SIZE];
280 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
282 bool operator==(const CodecInst& other) const {
283 return pltype == other.pltype &&
284 (STR_CASE_CMP(plname, other.plname) == 0) &&
285 plfreq == other.plfreq &&
286 pacsize == other.pacsize &&
287 channels == other.channels &&
291 bool operator!=(const CodecInst& other) const {
292 return !(*this == other);
297 enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
305 enum PayloadFrequencies
308 kFreq16000Hz = 16000,
312 enum VadModes // degree of bandwidth reduction
314 kVadConventional = 0, // lowest reduction
317 kVadAggressiveHigh // highest reduction
320 struct NetworkStatistics // NETEQ statistics
322 // current jitter buffer size in ms
323 uint16_t currentBufferSize;
324 // preferred (optimal) buffer size in ms
325 uint16_t preferredBufferSize;
326 // adding extra delay due to "peaky jitter"
327 bool jitterPeaksFound;
328 // loss rate (network + late) in percent (in Q14)
329 uint16_t currentPacketLossRate;
330 // late loss rate in percent (in Q14)
331 uint16_t currentDiscardRate;
332 // fraction (of original stream) of synthesized speech inserted through
333 // expansion (in Q14)
334 uint16_t currentExpandRate;
335 // fraction of synthesized speech inserted through pre-emptive expansion
337 uint16_t currentPreemptiveRate;
338 // fraction of data removed through acceleration (in Q14)
339 uint16_t currentAccelerateRate;
340 // clock-drift in parts-per-million (negative or positive)
341 int32_t clockDriftPPM;
342 // average packet waiting time in the jitter buffer (ms)
343 int meanWaitingTimeMs;
344 // median packet waiting time in the jitter buffer (ms)
345 int medianWaitingTimeMs;
346 // min packet waiting time in the jitter buffer (ms)
347 int minWaitingTimeMs;
348 // max packet waiting time in the jitter buffer (ms)
349 int maxWaitingTimeMs;
350 // added samples in off mode due to packet loss
354 // Statistics for calls to AudioCodingModule::PlayoutData10Ms().
355 struct AudioDecodingCallStats {
356 AudioDecodingCallStats()
357 : calls_to_silence_generator(0),
362 decoded_plc_cng(0) {}
364 int calls_to_silence_generator; // Number of calls where silence generated,
365 // and NetEq was disengaged from decoding.
366 int calls_to_neteq; // Number of calls to NetEq.
367 int decoded_normal; // Number of calls where audio RTP packet decoded.
368 int decoded_plc; // Number of calls resulted in PLC.
369 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
370 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
377 int average; // average
380 typedef struct // All levels are reported in dBm0
382 StatVal speech_rx; // long-term speech levels on receiving side
383 StatVal speech_tx; // long-term speech levels on transmitting side
384 StatVal noise_rx; // long-term noise/silence levels on receiving side
385 StatVal noise_tx; // long-term noise/silence levels on transmitting side
388 typedef struct // All levels are reported in dB
390 StatVal erl; // Echo Return Loss
391 StatVal erle; // Echo Return Loss Enhancement
392 StatVal rerl; // RERL = ERL + ERLE
393 // Echo suppression inside EC at the point just before its NLP
397 enum NsModes // type of Noise Suppression
399 kNsUnchanged = 0, // previously set mode
400 kNsDefault, // platform default
401 kNsConference, // conferencing default
402 kNsLowSuppression, // lowest suppression
403 kNsModerateSuppression,
405 kNsVeryHighSuppression, // highest suppression
408 enum AgcModes // type of Automatic Gain Control
410 kAgcUnchanged = 0, // previously set mode
411 kAgcDefault, // platform default
412 // adaptive mode for use when analog volume control exists (e.g. for
415 // scaling takes place in the digital domain (e.g. for conference servers
416 // and embedded devices)
418 // can be used on embedded devices where the capture signal level
424 enum EcModes // type of Echo Control
426 kEcUnchanged = 0, // previously set mode
427 kEcDefault, // platform default
428 kEcConference, // conferencing default (aggressive AEC)
429 kEcAec, // Acoustic Echo Cancellation
430 kEcAecm, // AEC mobile
434 enum AecmModes // mode of AECM
436 kAecmQuietEarpieceOrHeadset = 0,
437 // Quiet earpiece or headset use
438 kAecmEarpiece, // most earpiece use
439 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
440 kAecmSpeakerphone, // most speakerphone use (default)
441 kAecmLoudSpeakerphone // Loud speakerphone
447 unsigned short targetLeveldBOv;
448 unsigned short digitalCompressionGaindB;
450 } AgcConfig; // AGC configuration parameters
459 // Audio device layers
462 kAudioPlatformDefault = 0,
463 kAudioWindowsWave = 1,
464 kAudioWindowsCore = 2,
469 // TODO(henrika): to be removed.
470 enum NetEqModes // NetEQ playout configurations
472 // Optimized trade-off between low delay and jitter robustness for two-way
475 // Improved jitter robustness at the cost of increased delay. Can be
476 // used in one-way communication.
478 // Optimzed for decodability of fax signals rather than for perceived audio
481 // Minimal buffer management. Inserts zeros for lost packets and during
486 // TODO(henrika): to be removed.
487 enum OnHoldModes // On Hold direction
489 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
490 kHoldSendOnly, // Put only sending in on-hold state.
491 kHoldPlayOnly // Put only playing in on-hold state.
494 // TODO(henrika): to be removed.
497 kRfc3267BwEfficient = 0,
498 kRfc3267OctetAligned = 1,
499 kRfc3267FileStorage = 2,
502 // ==================================================================
503 // Video specific types
504 // ==================================================================
527 enum { kConfigParameterSize = 128};
528 enum { kPayloadNameSize = 32};
529 enum { kMaxSimulcastStreams = 4};
530 enum { kMaxTemporalStreams = 4};
532 enum VideoCodecComplexity
534 kComplexityNormal = 0,
536 kComplexityHigher = 2,
540 enum VideoCodecProfile
546 enum VP8ResilienceMode {
547 kResilienceOff, // The stream produced by the encoder requires a
548 // recovery frame (typically a key frame) to be
549 // decodable after a packet loss.
550 kResilientStream, // A stream produced by the encoder is resilient to
551 // packet losses, but packets within a frame subsequent
552 // to a loss can't be decoded.
553 kResilientFrames // Same as kResilientStream but with added resilience
558 struct VideoCodecVP8 {
559 bool pictureLossIndicationOn;
561 VideoCodecComplexity complexity;
562 VP8ResilienceMode resilience;
563 unsigned char numberOfTemporalLayers;
565 bool errorConcealmentOn;
566 bool automaticResizeOn;
567 bool frameDroppingOn;
568 int keyFrameInterval;
570 bool operator==(const VideoCodecVP8& other) const {
571 return pictureLossIndicationOn == other.pictureLossIndicationOn &&
572 feedbackModeOn == other.feedbackModeOn &&
573 complexity == other.complexity &&
574 resilience == other.resilience &&
575 numberOfTemporalLayers == other.numberOfTemporalLayers &&
576 denoisingOn == other.denoisingOn &&
577 errorConcealmentOn == other.errorConcealmentOn &&
578 automaticResizeOn == other.automaticResizeOn &&
579 frameDroppingOn == other.frameDroppingOn &&
580 keyFrameInterval == other.keyFrameInterval;
583 bool operator!=(const VideoCodecVP8& other) const {
584 return !(*this == other);
599 union VideoCodecUnion
605 // Simulcast is when the same stream is encoded multiple times with different
606 // settings such as resolution.
607 struct SimulcastStream {
608 unsigned short width;
609 unsigned short height;
610 unsigned char numberOfTemporalLayers;
611 unsigned int maxBitrate; // kilobits/sec.
612 unsigned int targetBitrate; // kilobits/sec.
613 unsigned int minBitrate; // kilobits/sec.
614 unsigned int qpMax; // minimum quality
616 bool operator==(const SimulcastStream& other) const {
617 return width == other.width &&
618 height == other.height &&
619 numberOfTemporalLayers == other.numberOfTemporalLayers &&
620 maxBitrate == other.maxBitrate &&
621 targetBitrate == other.targetBitrate &&
622 minBitrate == other.minBitrate &&
623 qpMax == other.qpMax;
626 bool operator!=(const SimulcastStream& other) const {
627 return !(*this == other);
631 enum VideoCodecMode {
636 // Common video codec properties
638 VideoCodecType codecType;
639 char plName[kPayloadNameSize];
640 unsigned char plType;
642 unsigned short width;
643 unsigned short height;
645 unsigned int startBitrate; // kilobits/sec.
646 unsigned int maxBitrate; // kilobits/sec.
647 unsigned int minBitrate; // kilobits/sec.
648 unsigned int targetBitrate; // kilobits/sec.
650 unsigned char maxFramerate;
652 VideoCodecUnion codecSpecific;
655 unsigned char numberOfSimulcastStreams;
656 SimulcastStream simulcastStream[kMaxSimulcastStreams];
660 // When using an external encoder/decoder this allows to pass
661 // extra options without requiring webrtc to be aware of them.
662 Config* extra_options;
664 bool operator==(const VideoCodec& other) const {
665 bool ret = codecType == other.codecType &&
666 (STR_CASE_CMP(plName, other.plName) == 0) &&
667 plType == other.plType &&
668 width == other.width &&
669 height == other.height &&
670 startBitrate == other.startBitrate &&
671 maxBitrate == other.maxBitrate &&
672 minBitrate == other.minBitrate &&
673 targetBitrate == other.targetBitrate &&
674 maxFramerate == other.maxFramerate &&
675 qpMax == other.qpMax &&
676 numberOfSimulcastStreams == other.numberOfSimulcastStreams &&
678 if (ret && codecType == kVideoCodecVP8) {
679 ret &= (codecSpecific.VP8 == other.codecSpecific.VP8);
682 for (unsigned char i = 0; i < other.numberOfSimulcastStreams && ret; ++i) {
683 ret &= (simulcastStream[i] == other.simulcastStream[i]);
688 bool operator!=(const VideoCodec& other) const {
689 return !(*this == other);
693 // Bandwidth over-use detector options. These are used to drive
694 // experimentation with bandwidth estimation parameters.
695 // See modules/remote_bitrate_estimator/overuse_detector.h
696 struct OverUseDetectorOptions {
697 OverUseDetectorOptions()
698 : initial_slope(8.0/512.0),
701 initial_process_noise(),
702 initial_avg_noise(0.0),
703 initial_var_noise(50),
704 initial_threshold(25.0) {
705 initial_e[0][0] = 100;
706 initial_e[1][1] = 1e-1;
707 initial_e[0][1] = initial_e[1][0] = 0;
708 initial_process_noise[0] = 1e-10;
709 initial_process_noise[1] = 1e-2;
711 double initial_slope;
712 double initial_offset;
713 double initial_e[2][2];
714 double initial_process_noise[2];
715 double initial_avg_noise;
716 double initial_var_noise;
717 double initial_threshold;
720 // This structure will have the information about when packet is actually
721 // received by socket.
723 PacketTime() : timestamp(-1), not_before(-1) {}
724 PacketTime(int64_t timestamp, int64_t not_before)
725 : timestamp(timestamp), not_before(not_before) {
728 int64_t timestamp; // Receive time after socket delivers the data.
729 int64_t not_before; // Earliest possible time the data could have arrived,
730 // indicating the potential error in the |timestamp|
731 // value,in case the system is busy.
732 // For example, the time of the last select() call.
733 // If unknown, this value will be set to zero.
736 struct RTPHeaderExtension {
738 : hasTransmissionTimeOffset(false),
739 transmissionTimeOffset(0),
740 hasAbsoluteSendTime(false),
742 hasAudioLevel(false),
745 bool hasTransmissionTimeOffset;
746 int32_t transmissionTimeOffset;
747 bool hasAbsoluteSendTime;
748 uint32_t absoluteSendTime;
750 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
751 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
766 payload_type_frequency(0),
768 memset(&arrOfCSRCs, 0, sizeof(arrOfCSRCs));
773 uint16_t sequenceNumber;
777 uint32_t arrOfCSRCs[kRtpCsrcSize];
778 uint8_t paddingLength;
779 uint16_t headerLength;
780 int payload_type_frequency;
781 RTPHeaderExtension extension;
790 target_bitrate_bps(-1),
799 int target_bitrate_bps;
804 // Bitrate thresholds for enabling additional temporal layers.
805 std::vector<int> temporal_layers;
808 } // namespace webrtc
810 #endif // WEBRTC_COMMON_TYPES_H_