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 <stddef.h>
15 #include <string.h>
16 
17 #include <string>
18 #include <vector>
19 
20 #include "webrtc/typedefs.h"
21 
22 #if defined(_MSC_VER)
23 // Disable "new behavior: elements of array will be default initialized"
24 // warning. Affects OverUseDetectorOptions.
25 #pragma warning(disable:4351)
26 #endif
27 
28 #ifdef WEBRTC_EXPORT
29 #define WEBRTC_DLLEXPORT _declspec(dllexport)
30 #elif WEBRTC_DLL
31 #define WEBRTC_DLLEXPORT _declspec(dllimport)
32 #else
33 #define WEBRTC_DLLEXPORT
34 #endif
35 
36 #ifndef NULL
37 #define NULL 0
38 #endif
39 
40 #define RTP_PAYLOAD_NAME_SIZE 32
41 
42 #if defined(WEBRTC_WIN) || defined(WIN32)
43 // Compares two strings without regard to case.
44 #define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
45 // Compares characters of two strings without regard to case.
46 #define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
47 #else
48 #define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
49 #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
50 #endif
51 
52 namespace webrtc {
53 
54 class Config;
55 
56 class InStream
57 {
58 public:
59  // Reads |length| bytes from file to |buf|. Returns the number of bytes read
60  // or -1 on error.
61     virtual int Read(void *buf, size_t len) = 0;
62     virtual int Rewind();
~InStream()63     virtual ~InStream() {}
64 protected:
InStream()65     InStream() {}
66 };
67 
68 class OutStream
69 {
70 public:
71  // Writes |length| bytes from |buf| to file. The actual writing may happen
72  // some time later. Call Flush() to force a write.
73     virtual bool Write(const void *buf, size_t len) = 0;
74     virtual int Rewind();
~OutStream()75     virtual ~OutStream() {}
76 protected:
OutStream()77     OutStream() {}
78 };
79 
80 enum TraceModule
81 {
82     kTraceUndefined              = 0,
83     // not a module, triggered from the engine code
84     kTraceVoice                  = 0x0001,
85     // not a module, triggered from the engine code
86     kTraceVideo                  = 0x0002,
87     // not a module, triggered from the utility code
88     kTraceUtility                = 0x0003,
89     kTraceRtpRtcp                = 0x0004,
90     kTraceTransport              = 0x0005,
91     kTraceSrtp                   = 0x0006,
92     kTraceAudioCoding            = 0x0007,
93     kTraceAudioMixerServer       = 0x0008,
94     kTraceAudioMixerClient       = 0x0009,
95     kTraceFile                   = 0x000a,
96     kTraceAudioProcessing        = 0x000b,
97     kTraceVideoCoding            = 0x0010,
98     kTraceVideoMixer             = 0x0011,
99     kTraceAudioDevice            = 0x0012,
100     kTraceVideoRenderer          = 0x0014,
101     kTraceVideoCapture           = 0x0015,
102     kTraceRemoteBitrateEstimator = 0x0017,
103 };
104 
105 enum TraceLevel
106 {
107     kTraceNone               = 0x0000,    // no trace
108     kTraceStateInfo          = 0x0001,
109     kTraceWarning            = 0x0002,
110     kTraceError              = 0x0004,
111     kTraceCritical           = 0x0008,
112     kTraceApiCall            = 0x0010,
113     kTraceDefault            = 0x00ff,
114 
115     kTraceModuleCall         = 0x0020,
116     kTraceMemory             = 0x0100,   // memory info
117     kTraceTimer              = 0x0200,   // timing info
118     kTraceStream             = 0x0400,   // "continuous" stream of data
119 
120     // used for debug purposes
121     kTraceDebug              = 0x0800,  // debug
122     kTraceInfo               = 0x1000,  // debug info
123 
124     // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
125     kTraceTerseInfo          = 0x2000,
126 
127     kTraceAll                = 0xffff
128 };
129 
130 // External Trace API
131 class TraceCallback {
132  public:
133   virtual void Print(TraceLevel level, const char* message, int length) = 0;
134 
135  protected:
~TraceCallback()136   virtual ~TraceCallback() {}
TraceCallback()137   TraceCallback() {}
138 };
139 
140 enum FileFormats
141 {
142     kFileFormatWavFile        = 1,
143     kFileFormatCompressedFile = 2,
144     kFileFormatPreencodedFile = 4,
145     kFileFormatPcm16kHzFile   = 7,
146     kFileFormatPcm8kHzFile    = 8,
147     kFileFormatPcm32kHzFile   = 9
148 };
149 
150 enum ProcessingTypes
151 {
152     kPlaybackPerChannel = 0,
153     kPlaybackAllChannelsMixed,
154     kRecordingPerChannel,
155     kRecordingAllChannelsMixed,
156     kRecordingPreprocessing
157 };
158 
159 enum FrameType {
160   kEmptyFrame = 0,
161   kAudioFrameSpeech = 1,
162   kAudioFrameCN = 2,
163   kVideoFrameKey = 3,
164   kVideoFrameDelta = 4,
165 };
166 
167 // Statistics for an RTCP channel
168 struct RtcpStatistics {
RtcpStatisticsRtcpStatistics169   RtcpStatistics()
170     : fraction_lost(0),
171       cumulative_lost(0),
172       extended_max_sequence_number(0),
173       jitter(0) {}
174 
175   uint8_t fraction_lost;
176   uint32_t cumulative_lost;
177   uint32_t extended_max_sequence_number;
178   uint32_t jitter;
179 };
180 
181 class RtcpStatisticsCallback {
182  public:
~RtcpStatisticsCallback()183   virtual ~RtcpStatisticsCallback() {}
184 
185   virtual void StatisticsUpdated(const RtcpStatistics& statistics,
186                                  uint32_t ssrc) = 0;
187   virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
188 };
189 
190 // Statistics for RTCP packet types.
191 struct RtcpPacketTypeCounter {
RtcpPacketTypeCounterRtcpPacketTypeCounter192   RtcpPacketTypeCounter()
193     : first_packet_time_ms(-1),
194       nack_packets(0),
195       fir_packets(0),
196       pli_packets(0),
197       nack_requests(0),
198       unique_nack_requests(0) {}
199 
AddRtcpPacketTypeCounter200   void Add(const RtcpPacketTypeCounter& other) {
201     nack_packets += other.nack_packets;
202     fir_packets += other.fir_packets;
203     pli_packets += other.pli_packets;
204     nack_requests += other.nack_requests;
205     unique_nack_requests += other.unique_nack_requests;
206     if (other.first_packet_time_ms != -1 &&
207        (other.first_packet_time_ms < first_packet_time_ms ||
208         first_packet_time_ms == -1)) {
209       // Use oldest time.
210       first_packet_time_ms = other.first_packet_time_ms;
211     }
212   }
213 
TimeSinceFirstPacketInMsRtcpPacketTypeCounter214   int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
215     return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
216   }
217 
UniqueNackRequestsInPercentRtcpPacketTypeCounter218   int UniqueNackRequestsInPercent() const {
219     if (nack_requests == 0) {
220       return 0;
221     }
222     return static_cast<int>(
223         (unique_nack_requests * 100.0f / nack_requests) + 0.5f);
224   }
225 
226   int64_t first_packet_time_ms;  // Time when first packet is sent/received.
227   uint32_t nack_packets;   // Number of RTCP NACK packets.
228   uint32_t fir_packets;    // Number of RTCP FIR packets.
229   uint32_t pli_packets;    // Number of RTCP PLI packets.
230   uint32_t nack_requests;  // Number of NACKed RTP packets.
231   uint32_t unique_nack_requests;  // Number of unique NACKed RTP packets.
232 };
233 
234 class RtcpPacketTypeCounterObserver {
235  public:
~RtcpPacketTypeCounterObserver()236   virtual ~RtcpPacketTypeCounterObserver() {}
237   virtual void RtcpPacketTypesCounterUpdated(
238       uint32_t ssrc,
239       const RtcpPacketTypeCounter& packet_counter) = 0;
240 };
241 
242 // Rate statistics for a stream.
243 struct BitrateStatistics {
BitrateStatisticsBitrateStatistics244   BitrateStatistics() : bitrate_bps(0), packet_rate(0), timestamp_ms(0) {}
245 
246   uint32_t bitrate_bps;   // Bitrate in bits per second.
247   uint32_t packet_rate;   // Packet rate in packets per second.
248   uint64_t timestamp_ms;  // Ntp timestamp in ms at time of rate estimation.
249 };
250 
251 // Callback, used to notify an observer whenever new rates have been estimated.
252 class BitrateStatisticsObserver {
253  public:
~BitrateStatisticsObserver()254   virtual ~BitrateStatisticsObserver() {}
255 
256   virtual void Notify(const BitrateStatistics& total_stats,
257                       const BitrateStatistics& retransmit_stats,
258                       uint32_t ssrc) = 0;
259 };
260 
261 struct FrameCounts {
FrameCountsFrameCounts262   FrameCounts() : key_frames(0), delta_frames(0) {}
263   int key_frames;
264   int delta_frames;
265 };
266 
267 // Callback, used to notify an observer whenever frame counts have been updated.
268 class FrameCountObserver {
269  public:
~FrameCountObserver()270   virtual ~FrameCountObserver() {}
271   virtual void FrameCountUpdated(const FrameCounts& frame_counts,
272                                  uint32_t ssrc) = 0;
273 };
274 
275 // Callback, used to notify an observer whenever the send-side delay is updated.
276 class SendSideDelayObserver {
277  public:
~SendSideDelayObserver()278   virtual ~SendSideDelayObserver() {}
279   virtual void SendSideDelayUpdated(int avg_delay_ms,
280                                     int max_delay_ms,
281                                     uint32_t ssrc) = 0;
282 };
283 
284 // ==================================================================
285 // Voice specific types
286 // ==================================================================
287 
288 // Each codec supported can be described by this structure.
289 struct CodecInst {
290   int pltype;
291   char plname[RTP_PAYLOAD_NAME_SIZE];
292   int plfreq;
293   int pacsize;
294   size_t channels;
295   int rate;  // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
296 
297   bool operator==(const CodecInst& other) const {
298     return pltype == other.pltype &&
299            (STR_CASE_CMP(plname, other.plname) == 0) &&
300            plfreq == other.plfreq &&
301            pacsize == other.pacsize &&
302            channels == other.channels &&
303            rate == other.rate;
304   }
305 
306   bool operator!=(const CodecInst& other) const {
307     return !(*this == other);
308   }
309 };
310 
311 // RTP
312 enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
313 
314 enum PayloadFrequencies
315 {
316     kFreq8000Hz = 8000,
317     kFreq16000Hz = 16000,
318     kFreq32000Hz = 32000
319 };
320 
321 enum VadModes                 // degree of bandwidth reduction
322 {
323     kVadConventional = 0,      // lowest reduction
324     kVadAggressiveLow,
325     kVadAggressiveMid,
326     kVadAggressiveHigh         // highest reduction
327 };
328 
329 struct NetworkStatistics           // NETEQ statistics
330 {
331     // current jitter buffer size in ms
332     uint16_t currentBufferSize;
333     // preferred (optimal) buffer size in ms
334     uint16_t preferredBufferSize;
335     // adding extra delay due to "peaky jitter"
336     bool jitterPeaksFound;
337     // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
338     uint16_t currentPacketLossRate;
339     // Late loss rate; fraction between 0 and 1, scaled to Q14.
340     uint16_t currentDiscardRate;
341     // fraction (of original stream) of synthesized audio inserted through
342     // expansion (in Q14)
343     uint16_t currentExpandRate;
344     // fraction (of original stream) of synthesized speech inserted through
345     // expansion (in Q14)
346     uint16_t currentSpeechExpandRate;
347     // fraction of synthesized speech inserted through pre-emptive expansion
348     // (in Q14)
349     uint16_t currentPreemptiveRate;
350     // fraction of data removed through acceleration (in Q14)
351     uint16_t currentAccelerateRate;
352     // fraction of data coming from secondary decoding (in Q14)
353     uint16_t currentSecondaryDecodedRate;
354     // clock-drift in parts-per-million (negative or positive)
355     int32_t clockDriftPPM;
356     // average packet waiting time in the jitter buffer (ms)
357     int meanWaitingTimeMs;
358     // median packet waiting time in the jitter buffer (ms)
359     int medianWaitingTimeMs;
360     // min packet waiting time in the jitter buffer (ms)
361     int minWaitingTimeMs;
362     // max packet waiting time in the jitter buffer (ms)
363     int maxWaitingTimeMs;
364     // added samples in off mode due to packet loss
365     size_t addedSamples;
366 };
367 
368 // Statistics for calls to AudioCodingModule::PlayoutData10Ms().
369 struct AudioDecodingCallStats {
AudioDecodingCallStatsAudioDecodingCallStats370   AudioDecodingCallStats()
371       : calls_to_silence_generator(0),
372         calls_to_neteq(0),
373         decoded_normal(0),
374         decoded_plc(0),
375         decoded_cng(0),
376         decoded_plc_cng(0) {}
377 
378   int calls_to_silence_generator;  // Number of calls where silence generated,
379                                    // and NetEq was disengaged from decoding.
380   int calls_to_neteq;  // Number of calls to NetEq.
381   int decoded_normal;  // Number of calls where audio RTP packet decoded.
382   int decoded_plc;  // Number of calls resulted in PLC.
383   int decoded_cng;  // Number of calls where comfort noise generated due to DTX.
384   int decoded_plc_cng;  // Number of calls resulted where PLC faded to CNG.
385 };
386 
387 typedef struct
388 {
389     int min;              // minumum
390     int max;              // maximum
391     int average;          // average
392 } StatVal;
393 
394 typedef struct           // All levels are reported in dBm0
395 {
396     StatVal speech_rx;   // long-term speech levels on receiving side
397     StatVal speech_tx;   // long-term speech levels on transmitting side
398     StatVal noise_rx;    // long-term noise/silence levels on receiving side
399     StatVal noise_tx;    // long-term noise/silence levels on transmitting side
400 } LevelStatistics;
401 
402 typedef struct        // All levels are reported in dB
403 {
404     StatVal erl;      // Echo Return Loss
405     StatVal erle;     // Echo Return Loss Enhancement
406     StatVal rerl;     // RERL = ERL + ERLE
407     // Echo suppression inside EC at the point just before its NLP
408     StatVal a_nlp;
409 } EchoStatistics;
410 
411 enum NsModes    // type of Noise Suppression
412 {
413     kNsUnchanged = 0,   // previously set mode
414     kNsDefault,         // platform default
415     kNsConference,      // conferencing default
416     kNsLowSuppression,  // lowest suppression
417     kNsModerateSuppression,
418     kNsHighSuppression,
419     kNsVeryHighSuppression,     // highest suppression
420 };
421 
422 enum AgcModes                  // type of Automatic Gain Control
423 {
424     kAgcUnchanged = 0,        // previously set mode
425     kAgcDefault,              // platform default
426     // adaptive mode for use when analog volume control exists (e.g. for
427     // PC softphone)
428     kAgcAdaptiveAnalog,
429     // scaling takes place in the digital domain (e.g. for conference servers
430     // and embedded devices)
431     kAgcAdaptiveDigital,
432     // can be used on embedded devices where the capture signal level
433     // is predictable
434     kAgcFixedDigital
435 };
436 
437 // EC modes
438 enum EcModes                   // type of Echo Control
439 {
440     kEcUnchanged = 0,          // previously set mode
441     kEcDefault,                // platform default
442     kEcConference,             // conferencing default (aggressive AEC)
443     kEcAec,                    // Acoustic Echo Cancellation
444     kEcAecm,                   // AEC mobile
445 };
446 
447 // AECM modes
448 enum AecmModes                 // mode of AECM
449 {
450     kAecmQuietEarpieceOrHeadset = 0,
451                                // Quiet earpiece or headset use
452     kAecmEarpiece,             // most earpiece use
453     kAecmLoudEarpiece,         // Loud earpiece or quiet speakerphone use
454     kAecmSpeakerphone,         // most speakerphone use (default)
455     kAecmLoudSpeakerphone      // Loud speakerphone
456 };
457 
458 // AGC configuration
459 typedef struct
460 {
461     unsigned short targetLeveldBOv;
462     unsigned short digitalCompressionGaindB;
463     bool           limiterEnable;
464 } AgcConfig;                  // AGC configuration parameters
465 
466 enum StereoChannel
467 {
468     kStereoLeft = 0,
469     kStereoRight,
470     kStereoBoth
471 };
472 
473 // Audio device layers
474 enum AudioLayers
475 {
476     kAudioPlatformDefault = 0,
477     kAudioWindowsWave = 1,
478     kAudioWindowsCore = 2,
479     kAudioLinuxAlsa = 3,
480     kAudioLinuxPulse = 4
481 };
482 
483 // TODO(henrika): to be removed.
484 enum NetEqModes             // NetEQ playout configurations
485 {
486     // Optimized trade-off between low delay and jitter robustness for two-way
487     // communication.
488     kNetEqDefault = 0,
489     // Improved jitter robustness at the cost of increased delay. Can be
490     // used in one-way communication.
491     kNetEqStreaming = 1,
492     // Optimzed for decodability of fax signals rather than for perceived audio
493     // quality.
494     kNetEqFax = 2,
495     // Minimal buffer management. Inserts zeros for lost packets and during
496     // buffer increases.
497     kNetEqOff = 3,
498 };
499 
500 // TODO(henrika): to be removed.
501 enum OnHoldModes            // On Hold direction
502 {
503     kHoldSendAndPlay = 0,    // Put both sending and playing in on-hold state.
504     kHoldSendOnly,           // Put only sending in on-hold state.
505     kHoldPlayOnly            // Put only playing in on-hold state.
506 };
507 
508 // TODO(henrika): to be removed.
509 enum AmrMode
510 {
511     kRfc3267BwEfficient = 0,
512     kRfc3267OctetAligned = 1,
513     kRfc3267FileStorage = 2,
514 };
515 
516 // ==================================================================
517 // Video specific types
518 // ==================================================================
519 
520 // Raw video types
521 enum RawVideoType
522 {
523     kVideoI420     = 0,
524     kVideoYV12     = 1,
525     kVideoYUY2     = 2,
526     kVideoUYVY     = 3,
527     kVideoIYUV     = 4,
528     kVideoARGB     = 5,
529     kVideoRGB24    = 6,
530     kVideoRGB565   = 7,
531     kVideoARGB4444 = 8,
532     kVideoARGB1555 = 9,
533     kVideoMJPEG    = 10,
534     kVideoNV12     = 11,
535     kVideoNV21     = 12,
536     kVideoBGRA     = 13,
537     kVideoUnknown  = 99
538 };
539 
540 // Video codec
541 enum { kConfigParameterSize = 128};
542 enum { kPayloadNameSize = 32};
543 enum { kMaxSimulcastStreams = 4};
544 enum { kMaxSpatialLayers = 5 };
545 enum { kMaxTemporalStreams = 4};
546 
547 enum VideoCodecComplexity
548 {
549     kComplexityNormal = 0,
550     kComplexityHigh    = 1,
551     kComplexityHigher  = 2,
552     kComplexityMax     = 3
553 };
554 
555 enum VideoCodecProfile
556 {
557     kProfileBase = 0x00,
558     kProfileMain = 0x01
559 };
560 
561 enum VP8ResilienceMode {
562   kResilienceOff,    // The stream produced by the encoder requires a
563                      // recovery frame (typically a key frame) to be
564                      // decodable after a packet loss.
565   kResilientStream,  // A stream produced by the encoder is resilient to
566                      // packet losses, but packets within a frame subsequent
567                      // to a loss can't be decoded.
568   kResilientFrames   // Same as kResilientStream but with added resilience
569                      // within a frame.
570 };
571 
572 // VP8 specific
573 struct VideoCodecVP8 {
574   bool                 pictureLossIndicationOn;
575   bool                 feedbackModeOn;
576   VideoCodecComplexity complexity;
577   VP8ResilienceMode    resilience;
578   unsigned char        numberOfTemporalLayers;
579   bool                 denoisingOn;
580   bool                 errorConcealmentOn;
581   bool                 automaticResizeOn;
582   bool                 frameDroppingOn;
583   int                  keyFrameInterval;
584 
585   bool operator==(const VideoCodecVP8& other) const {
586     return pictureLossIndicationOn == other.pictureLossIndicationOn &&
587            feedbackModeOn == other.feedbackModeOn &&
588            complexity == other.complexity &&
589            resilience == other.resilience &&
590            numberOfTemporalLayers == other.numberOfTemporalLayers &&
591            denoisingOn == other.denoisingOn &&
592            errorConcealmentOn == other.errorConcealmentOn &&
593            automaticResizeOn == other.automaticResizeOn &&
594            frameDroppingOn == other.frameDroppingOn &&
595            keyFrameInterval == other.keyFrameInterval;
596   }
597 
598   bool operator!=(const VideoCodecVP8& other) const {
599     return !(*this == other);
600   }
601 };
602 
603 // VP9 specific.
604 struct VideoCodecVP9 {
605   VideoCodecComplexity complexity;
606   int                  resilience;
607   unsigned char        numberOfTemporalLayers;
608   bool                 denoisingOn;
609   bool                 frameDroppingOn;
610   int                  keyFrameInterval;
611   bool                 adaptiveQpMode;
612   bool                 automaticResizeOn;
613   unsigned char        numberOfSpatialLayers;
614   bool                 flexibleMode;
615 };
616 
617 // H264 specific.
618 struct VideoCodecH264 {
619   VideoCodecProfile profile;
620   bool           frameDroppingOn;
621   int            keyFrameInterval;
622   // These are NULL/0 if not externally negotiated.
623   const uint8_t* spsData;
624   size_t         spsLen;
625   const uint8_t* ppsData;
626   size_t         ppsLen;
627 };
628 
629 // Video codec types
630 enum VideoCodecType {
631   kVideoCodecVP8,
632   kVideoCodecVP9,
633   kVideoCodecH264,
634   kVideoCodecI420,
635   kVideoCodecRED,
636   kVideoCodecULPFEC,
637   kVideoCodecGeneric,
638   kVideoCodecUnknown
639 };
640 
641 union VideoCodecUnion {
642   VideoCodecVP8       VP8;
643   VideoCodecVP9       VP9;
644   VideoCodecH264      H264;
645 };
646 
647 
648 // Simulcast is when the same stream is encoded multiple times with different
649 // settings such as resolution.
650 struct SimulcastStream {
651   unsigned short      width;
652   unsigned short      height;
653   unsigned char       numberOfTemporalLayers;
654   unsigned int        maxBitrate;  // kilobits/sec.
655   unsigned int        targetBitrate;  // kilobits/sec.
656   unsigned int        minBitrate;  // kilobits/sec.
657   unsigned int        qpMax; // minimum quality
658 
659   bool operator==(const SimulcastStream& other) const {
660     return width == other.width &&
661            height == other.height &&
662            numberOfTemporalLayers == other.numberOfTemporalLayers &&
663            maxBitrate == other.maxBitrate &&
664            targetBitrate == other.targetBitrate &&
665            minBitrate == other.minBitrate &&
666            qpMax == other.qpMax;
667   }
668 
669   bool operator!=(const SimulcastStream& other) const {
670     return !(*this == other);
671   }
672 };
673 
674 struct SpatialLayer {
675   int scaling_factor_num;
676   int scaling_factor_den;
677   int target_bitrate_bps;
678   // TODO(ivica): Add max_quantizer and min_quantizer?
679 };
680 
681 enum VideoCodecMode {
682   kRealtimeVideo,
683   kScreensharing
684 };
685 
686 // Common video codec properties
687 struct VideoCodec {
688   VideoCodecType      codecType;
689   char                plName[kPayloadNameSize];
690   unsigned char       plType;
691 
692   unsigned short      width;
693   unsigned short      height;
694 
695   unsigned int        startBitrate;  // kilobits/sec.
696   unsigned int        maxBitrate;  // kilobits/sec.
697   unsigned int        minBitrate;  // kilobits/sec.
698   unsigned int        targetBitrate;  // kilobits/sec.
699 
700   unsigned char       maxFramerate;
701 
702   VideoCodecUnion     codecSpecific;
703 
704   unsigned int        qpMax;
705   unsigned char       numberOfSimulcastStreams;
706   SimulcastStream     simulcastStream[kMaxSimulcastStreams];
707   SpatialLayer spatialLayers[kMaxSpatialLayers];
708 
709   VideoCodecMode      mode;
710 
711   // When using an external encoder/decoder this allows to pass
712   // extra options without requiring webrtc to be aware of them.
713   Config*  extra_options;
714 
715   bool operator==(const VideoCodec& other) const {
716     bool ret = codecType == other.codecType &&
717                (STR_CASE_CMP(plName, other.plName) == 0) &&
718                plType == other.plType &&
719                width == other.width &&
720                height == other.height &&
721                startBitrate == other.startBitrate &&
722                maxBitrate == other.maxBitrate &&
723                minBitrate == other.minBitrate &&
724                targetBitrate == other.targetBitrate &&
725                maxFramerate == other.maxFramerate &&
726                qpMax == other.qpMax &&
727                numberOfSimulcastStreams == other.numberOfSimulcastStreams &&
728                mode == other.mode;
729     if (ret && codecType == kVideoCodecVP8) {
730       ret &= (codecSpecific.VP8 == other.codecSpecific.VP8);
731     }
732 
733     for (unsigned char i = 0; i < other.numberOfSimulcastStreams && ret; ++i) {
734       ret &= (simulcastStream[i] == other.simulcastStream[i]);
735     }
736     return ret;
737   }
738 
739   bool operator!=(const VideoCodec& other) const {
740     return !(*this == other);
741   }
742 };
743 
744 // Bandwidth over-use detector options.  These are used to drive
745 // experimentation with bandwidth estimation parameters.
746 // See modules/remote_bitrate_estimator/overuse_detector.h
747 struct OverUseDetectorOptions {
OverUseDetectorOptionsOverUseDetectorOptions748   OverUseDetectorOptions()
749       : initial_slope(8.0/512.0),
750         initial_offset(0),
751         initial_e(),
752         initial_process_noise(),
753         initial_avg_noise(0.0),
754         initial_var_noise(50) {
755     initial_e[0][0] = 100;
756     initial_e[1][1] = 1e-1;
757     initial_e[0][1] = initial_e[1][0] = 0;
758     initial_process_noise[0] = 1e-13;
759     initial_process_noise[1] = 1e-2;
760   }
761   double initial_slope;
762   double initial_offset;
763   double initial_e[2][2];
764   double initial_process_noise[2];
765   double initial_avg_noise;
766   double initial_var_noise;
767 };
768 
769 // This structure will have the information about when packet is actually
770 // received by socket.
771 struct PacketTime {
PacketTimePacketTime772   PacketTime() : timestamp(-1), not_before(-1) {}
PacketTimePacketTime773   PacketTime(int64_t timestamp, int64_t not_before)
774       : timestamp(timestamp), not_before(not_before) {
775   }
776 
777   int64_t timestamp;   // Receive time after socket delivers the data.
778   int64_t not_before;  // Earliest possible time the data could have arrived,
779                        // indicating the potential error in the |timestamp|
780                        // value,in case the system is busy.
781                        // For example, the time of the last select() call.
782                        // If unknown, this value will be set to zero.
783 };
784 
785 struct RTPHeaderExtension {
786   RTPHeaderExtension();
787 
788   bool hasTransmissionTimeOffset;
789   int32_t transmissionTimeOffset;
790   bool hasAbsoluteSendTime;
791   uint32_t absoluteSendTime;
792   bool hasTransportSequenceNumber;
793   uint16_t transportSequenceNumber;
794 
795   // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
796   // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
797   bool hasAudioLevel;
798   bool voiceActivity;
799   uint8_t audioLevel;
800 
801   // For Coordination of Video Orientation. See
802   // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
803   // ts_126114v120700p.pdf
804   bool hasVideoRotation;
805   uint8_t videoRotation;
806 };
807 
808 struct RTPHeader {
809   RTPHeader();
810 
811   bool markerBit;
812   uint8_t payloadType;
813   uint16_t sequenceNumber;
814   uint32_t timestamp;
815   uint32_t ssrc;
816   uint8_t numCSRCs;
817   uint32_t arrOfCSRCs[kRtpCsrcSize];
818   size_t paddingLength;
819   size_t headerLength;
820   int payload_type_frequency;
821   RTPHeaderExtension extension;
822 };
823 
824 struct RtpPacketCounter {
RtpPacketCounterRtpPacketCounter825   RtpPacketCounter()
826     : header_bytes(0),
827       payload_bytes(0),
828       padding_bytes(0),
829       packets(0) {}
830 
AddRtpPacketCounter831   void Add(const RtpPacketCounter& other) {
832     header_bytes += other.header_bytes;
833     payload_bytes += other.payload_bytes;
834     padding_bytes += other.padding_bytes;
835     packets += other.packets;
836   }
837 
AddPacketRtpPacketCounter838   void AddPacket(size_t packet_length, const RTPHeader& header) {
839     ++packets;
840     header_bytes += header.headerLength;
841     padding_bytes += header.paddingLength;
842     payload_bytes +=
843         packet_length - (header.headerLength + header.paddingLength);
844   }
845 
TotalBytesRtpPacketCounter846   size_t TotalBytes() const {
847     return header_bytes + payload_bytes + padding_bytes;
848   }
849 
850   size_t header_bytes;   // Number of bytes used by RTP headers.
851   size_t payload_bytes;  // Payload bytes, excluding RTP headers and padding.
852   size_t padding_bytes;  // Number of padding bytes.
853   uint32_t packets;      // Number of packets.
854 };
855 
856 // Data usage statistics for a (rtp) stream.
857 struct StreamDataCounters {
858   StreamDataCounters();
859 
AddStreamDataCounters860   void Add(const StreamDataCounters& other) {
861     transmitted.Add(other.transmitted);
862     retransmitted.Add(other.retransmitted);
863     fec.Add(other.fec);
864     if (other.first_packet_time_ms != -1 &&
865        (other.first_packet_time_ms < first_packet_time_ms ||
866         first_packet_time_ms == -1)) {
867       // Use oldest time.
868       first_packet_time_ms = other.first_packet_time_ms;
869     }
870   }
871 
TimeSinceFirstPacketInMsStreamDataCounters872   int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
873     return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
874   }
875 
876   // Returns the number of bytes corresponding to the actual media payload (i.e.
877   // RTP headers, padding, retransmissions and fec packets are excluded).
878   // Note this function does not have meaning for an RTX stream.
MediaPayloadBytesStreamDataCounters879   size_t MediaPayloadBytes() const {
880     return transmitted.payload_bytes - retransmitted.payload_bytes -
881            fec.payload_bytes;
882   }
883 
884   int64_t first_packet_time_ms;  // Time when first packet is sent/received.
885   RtpPacketCounter transmitted;  // Number of transmitted packets/bytes.
886   RtpPacketCounter retransmitted;  // Number of retransmitted packets/bytes.
887   RtpPacketCounter fec;  // Number of redundancy packets/bytes.
888 };
889 
890 // Callback, called whenever byte/packet counts have been updated.
891 class StreamDataCountersCallback {
892  public:
~StreamDataCountersCallback()893   virtual ~StreamDataCountersCallback() {}
894 
895   virtual void DataCountersUpdated(const StreamDataCounters& counters,
896                                    uint32_t ssrc) = 0;
897 };
898 
899 // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
900 // RTCP mode is described by RFC 5506.
901 enum class RtcpMode { kOff, kCompound, kReducedSize };
902 
903 }  // namespace webrtc
904 
905 #endif  // WEBRTC_COMMON_TYPES_H_
906