LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc - common_types.h (source / functions) Hit Total Coverage
Test: output.info Lines: 1 135 0.7 %
Date: 2017-07-14 16:53:18 Functions: 1 67 1.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <ostream>
      18             : #include <string>
      19             : #include <vector>
      20             : 
      21             : #include "webrtc/api/video/video_rotation.h"
      22             : #include "webrtc/base/checks.h"
      23             : #include "webrtc/base/optional.h"
      24             : #include "webrtc/typedefs.h"
      25             : 
      26             : #if defined(_MSC_VER)
      27             : // Disable "new behavior: elements of array will be default initialized"
      28             : // warning. Affects OverUseDetectorOptions.
      29             : #pragma warning(disable : 4351)
      30             : #endif
      31             : 
      32             : #if defined(WEBRTC_EXPORT)
      33             : #define WEBRTC_DLLEXPORT _declspec(dllexport)
      34             : #elif defined(WEBRTC_DLL)
      35             : #define WEBRTC_DLLEXPORT _declspec(dllimport)
      36             : #else
      37             : #define WEBRTC_DLLEXPORT
      38             : #endif
      39             : 
      40             : #ifndef NULL
      41             : #define NULL 0
      42             : #endif
      43             : 
      44             : #define RTP_PAYLOAD_NAME_SIZE 32u
      45             : 
      46             : #if defined(WEBRTC_WIN) || defined(WIN32)
      47             : // Compares two strings without regard to case.
      48             : #define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
      49             : // Compares characters of two strings without regard to case.
      50             : #define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
      51             : #else
      52             : #define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
      53             : #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
      54             : #endif
      55             : 
      56             : namespace webrtc {
      57             : 
      58           0 : class RewindableStream {
      59             :  public:
      60           0 :   virtual ~RewindableStream() {}
      61             :   virtual int Rewind() = 0;
      62             : };
      63             : 
      64           0 : class InStream : public RewindableStream {
      65             :  public:
      66             :   // Reads |len| bytes from file to |buf|. Returns the number of bytes read
      67             :   // or -1 on error.
      68             :   virtual int Read(void* buf, size_t len) = 0;
      69             : };
      70             : 
      71           0 : class OutStream : public RewindableStream {
      72             :  public:
      73             :   // Writes |len| bytes from |buf| to file. The actual writing may happen
      74             :   // some time later. Call Flush() to force a write.
      75             :   virtual bool Write(const void* buf, size_t len) = 0;
      76             : };
      77             : 
      78             : enum TraceModule {
      79             :   kTraceUndefined = 0,
      80             :   // not a module, triggered from the engine code
      81             :   kTraceVoice = 0x0001,
      82             :   // not a module, triggered from the engine code
      83             :   kTraceVideo = 0x0002,
      84             :   // not a module, triggered from the utility code
      85             :   kTraceUtility = 0x0003,
      86             :   kTraceRtpRtcp = 0x0004,
      87             :   kTraceTransport = 0x0005,
      88             :   kTraceSrtp = 0x0006,
      89             :   kTraceAudioCoding = 0x0007,
      90             :   kTraceAudioMixerServer = 0x0008,
      91             :   kTraceAudioMixerClient = 0x0009,
      92             :   kTraceFile = 0x000a,
      93             :   kTraceAudioProcessing = 0x000b,
      94             :   kTraceVideoCoding = 0x0010,
      95             :   kTraceVideoMixer = 0x0011,
      96             :   kTraceAudioDevice = 0x0012,
      97             :   kTraceVideoRenderer = 0x0014,
      98             :   kTraceVideoCapture = 0x0015,
      99             :   kTraceRemoteBitrateEstimator = 0x0017,
     100             : };
     101             : 
     102             : enum TraceLevel {
     103             :   kTraceNone = 0x0000,  // no trace
     104             :   kTraceStateInfo = 0x0001,
     105             :   kTraceWarning = 0x0002,
     106             :   kTraceError = 0x0004,
     107             :   kTraceCritical = 0x0008,
     108             :   kTraceApiCall = 0x0010,
     109             :   kTraceDefault = 0x00ff,
     110             : 
     111             :   kTraceModuleCall = 0x0020,
     112             :   kTraceMemory = 0x0100,  // memory info
     113             :   kTraceTimer = 0x0200,   // timing info
     114             :   kTraceStream = 0x0400,  // "continuous" stream of data
     115             : 
     116             :   // used for debug purposes
     117             :   kTraceDebug = 0x0800,  // debug
     118             :   kTraceInfo = 0x1000,   // debug info
     119             : 
     120             :   // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
     121             :   kTraceTerseInfo = 0x2000,
     122             : 
     123             :   kTraceAll = 0xffff
     124             : };
     125             : 
     126             : // External Trace API
     127             : class TraceCallback {
     128             :  public:
     129             :   virtual void Print(TraceLevel level, const char* message, int length) = 0;
     130             : 
     131             :  protected:
     132           0 :   virtual ~TraceCallback() {}
     133           3 :   TraceCallback() {}
     134             : };
     135             : 
     136             : enum FileFormats {
     137             :   kFileFormatWavFile = 1,
     138             :   kFileFormatCompressedFile = 2,
     139             :   kFileFormatPreencodedFile = 4,
     140             :   kFileFormatPcm16kHzFile = 7,
     141             :   kFileFormatPcm8kHzFile = 8,
     142             :   kFileFormatPcm32kHzFile = 9
     143             : };
     144             : 
     145             : enum ProcessingTypes {
     146             :   kPlaybackPerChannel = 0,
     147             :   kPlaybackAllChannelsMixed,
     148             :   kRecordingPerChannel,
     149             :   kRecordingAllChannelsMixed,
     150             :   kRecordingPreprocessing
     151             : };
     152             : 
     153             : enum FrameType {
     154             :   kEmptyFrame = 0,
     155             :   kAudioFrameSpeech = 1,
     156             :   kAudioFrameCN = 2,
     157             :   kVideoFrameKey = 3,
     158             :   kVideoFrameDelta = 4,
     159             : };
     160             : 
     161             : // Statistics for an RTCP channel
     162             : struct RtcpStatistics {
     163           0 :   RtcpStatistics()
     164           0 :       : fraction_lost(0),
     165             :         cumulative_lost(0),
     166             :         extended_max_sequence_number(0),
     167           0 :         jitter(0) {}
     168             : 
     169             :   uint8_t fraction_lost;
     170             :   uint32_t cumulative_lost;
     171             :   uint32_t extended_max_sequence_number;
     172             :   uint32_t jitter;
     173             : };
     174             : 
     175           0 : class RtcpStatisticsCallback {
     176             :  public:
     177           0 :   virtual ~RtcpStatisticsCallback() {}
     178             : 
     179             :   virtual void StatisticsUpdated(const RtcpStatistics& statistics,
     180             :                                  uint32_t ssrc) = 0;
     181             :   virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
     182             : };
     183             : 
     184             : // Statistics for RTCP packet types.
     185             : struct RtcpPacketTypeCounter {
     186           0 :   RtcpPacketTypeCounter()
     187           0 :       : first_packet_time_ms(-1),
     188             :         nack_packets(0),
     189             :         fir_packets(0),
     190             :         pli_packets(0),
     191             :         nack_requests(0),
     192           0 :         unique_nack_requests(0) {}
     193             : 
     194           0 :   void Add(const RtcpPacketTypeCounter& other) {
     195           0 :     nack_packets += other.nack_packets;
     196           0 :     fir_packets += other.fir_packets;
     197           0 :     pli_packets += other.pli_packets;
     198           0 :     nack_requests += other.nack_requests;
     199           0 :     unique_nack_requests += other.unique_nack_requests;
     200           0 :     if (other.first_packet_time_ms != -1 &&
     201           0 :         (other.first_packet_time_ms < first_packet_time_ms ||
     202           0 :          first_packet_time_ms == -1)) {
     203             :       // Use oldest time.
     204           0 :       first_packet_time_ms = other.first_packet_time_ms;
     205             :     }
     206           0 :   }
     207             : 
     208           0 :   void Subtract(const RtcpPacketTypeCounter& other) {
     209           0 :     nack_packets -= other.nack_packets;
     210           0 :     fir_packets -= other.fir_packets;
     211           0 :     pli_packets -= other.pli_packets;
     212           0 :     nack_requests -= other.nack_requests;
     213           0 :     unique_nack_requests -= other.unique_nack_requests;
     214           0 :     if (other.first_packet_time_ms != -1 &&
     215           0 :         (other.first_packet_time_ms > first_packet_time_ms ||
     216           0 :          first_packet_time_ms == -1)) {
     217             :       // Use youngest time.
     218           0 :       first_packet_time_ms = other.first_packet_time_ms;
     219             :     }
     220           0 :   }
     221             : 
     222             :   int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
     223             :     return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
     224             :   }
     225             : 
     226           0 :   int UniqueNackRequestsInPercent() const {
     227           0 :     if (nack_requests == 0) {
     228           0 :       return 0;
     229             :     }
     230           0 :     return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
     231           0 :                             0.5f);
     232             :   }
     233             : 
     234             :   int64_t first_packet_time_ms;   // Time when first packet is sent/received.
     235             :   uint32_t nack_packets;          // Number of RTCP NACK packets.
     236             :   uint32_t fir_packets;           // Number of RTCP FIR packets.
     237             :   uint32_t pli_packets;           // Number of RTCP PLI packets.
     238             :   uint32_t nack_requests;         // Number of NACKed RTP packets.
     239             :   uint32_t unique_nack_requests;  // Number of unique NACKed RTP packets.
     240             : };
     241             : 
     242           0 : class RtcpPacketTypeCounterObserver {
     243             :  public:
     244           0 :   virtual ~RtcpPacketTypeCounterObserver() {}
     245             :   virtual void RtcpPacketTypesCounterUpdated(
     246             :       uint32_t ssrc,
     247             :       const RtcpPacketTypeCounter& packet_counter) = 0;
     248             : };
     249             : 
     250             : // Rate statistics for a stream.
     251             : struct BitrateStatistics {
     252             :   BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
     253             : 
     254             :   uint32_t bitrate_bps;  // Bitrate in bits per second.
     255             :   uint32_t packet_rate;  // Packet rate in packets per second.
     256             : };
     257             : 
     258             : // Callback, used to notify an observer whenever new rates have been estimated.
     259           0 : class BitrateStatisticsObserver {
     260             :  public:
     261           0 :   virtual ~BitrateStatisticsObserver() {}
     262             : 
     263             :   virtual void Notify(uint32_t total_bitrate_bps,
     264             :                       uint32_t retransmit_bitrate_bps,
     265             :                       uint32_t ssrc) = 0;
     266             : };
     267             : 
     268             : struct FrameCounts {
     269           0 :   FrameCounts() : key_frames(0), delta_frames(0) {}
     270             :   int key_frames;
     271             :   int delta_frames;
     272             : };
     273             : 
     274             : // Callback, used to notify an observer whenever frame counts have been updated.
     275           0 : class FrameCountObserver {
     276             :  public:
     277           0 :   virtual ~FrameCountObserver() {}
     278             :   virtual void FrameCountUpdated(const FrameCounts& frame_counts,
     279             :                                  uint32_t ssrc) = 0;
     280             : };
     281             : 
     282             : // Callback, used to notify an observer whenever the send-side delay is updated.
     283           0 : class SendSideDelayObserver {
     284             :  public:
     285           0 :   virtual ~SendSideDelayObserver() {}
     286             :   virtual void SendSideDelayUpdated(int avg_delay_ms,
     287             :                                     int max_delay_ms,
     288             :                                     uint32_t ssrc) = 0;
     289             : };
     290             : 
     291             : // Callback, used to notify an observer whenever a packet is sent to the
     292             : // transport.
     293             : // TODO(asapersson): This class will remove the need for SendSideDelayObserver.
     294             : // Remove SendSideDelayObserver once possible.
     295           0 : class SendPacketObserver {
     296             :  public:
     297           0 :   virtual ~SendPacketObserver() {}
     298             :   virtual void OnSendPacket(uint16_t packet_id,
     299             :                             int64_t capture_time_ms,
     300             :                             uint32_t ssrc) = 0;
     301             : };
     302             : 
     303             : // Callback, used to notify an observer when the overhead per packet
     304             : // has changed.
     305           0 : class OverheadObserver {
     306             :  public:
     307           0 :   virtual ~OverheadObserver() = default;
     308             :   virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
     309             : };
     310             : 
     311             : // ==================================================================
     312             : // Voice specific types
     313             : // ==================================================================
     314             : 
     315             : // Each codec supported can be described by this structure.
     316             : struct CodecInst {
     317             :   int pltype;
     318             :   char plname[RTP_PAYLOAD_NAME_SIZE];
     319             :   int plfreq;
     320             :   int pacsize;
     321             :   size_t channels;
     322             :   int rate;  // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
     323             : 
     324           0 :   bool operator==(const CodecInst& other) const {
     325           0 :     return pltype == other.pltype &&
     326           0 :            (STR_CASE_CMP(plname, other.plname) == 0) &&
     327           0 :            plfreq == other.plfreq && pacsize == other.pacsize &&
     328           0 :            channels == other.channels && rate == other.rate;
     329             :   }
     330             : 
     331           0 :   bool operator!=(const CodecInst& other) const { return !(*this == other); }
     332             : 
     333             :   friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
     334             :     os << "{pltype: " << ci.pltype;
     335             :     os << ", plname: " << ci.plname;
     336             :     os << ", plfreq: " << ci.plfreq;
     337             :     os << ", pacsize: " << ci.pacsize;
     338             :     os << ", channels: " << ci.channels;
     339             :     os << ", rate: " << ci.rate << "}";
     340             :     return os;
     341             :   }
     342             : };
     343             : 
     344             : // RTP
     345             : enum { kRtpCsrcSize = 15 };  // RFC 3550 page 13
     346             : 
     347             : enum PayloadFrequencies {
     348             :   kFreq8000Hz = 8000,
     349             :   kFreq16000Hz = 16000,
     350             :   kFreq32000Hz = 32000
     351             : };
     352             : 
     353             : // Degree of bandwidth reduction.
     354             : enum VadModes {
     355             :   kVadConventional = 0,  // lowest reduction
     356             :   kVadAggressiveLow,
     357             :   kVadAggressiveMid,
     358             :   kVadAggressiveHigh  // highest reduction
     359             : };
     360             : 
     361             : // NETEQ statistics.
     362             : struct NetworkStatistics {
     363             :   // current jitter buffer size in ms
     364             :   uint16_t currentBufferSize;
     365             :   // preferred (optimal) buffer size in ms
     366             :   uint16_t preferredBufferSize;
     367             :   // adding extra delay due to "peaky jitter"
     368             :   bool jitterPeaksFound;
     369             :   // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
     370             :   uint16_t currentPacketLossRate;
     371             :   // Late loss rate; fraction between 0 and 1, scaled to Q14.
     372             :   uint16_t currentDiscardRate;
     373             :   // fraction (of original stream) of synthesized audio inserted through
     374             :   // expansion (in Q14)
     375             :   uint16_t currentExpandRate;
     376             :   // fraction (of original stream) of synthesized speech inserted through
     377             :   // expansion (in Q14)
     378             :   uint16_t currentSpeechExpandRate;
     379             :   // fraction of synthesized speech inserted through pre-emptive expansion
     380             :   // (in Q14)
     381             :   uint16_t currentPreemptiveRate;
     382             :   // fraction of data removed through acceleration (in Q14)
     383             :   uint16_t currentAccelerateRate;
     384             :   // fraction of data coming from secondary decoding (in Q14)
     385             :   uint16_t currentSecondaryDecodedRate;
     386             :   // clock-drift in parts-per-million (negative or positive)
     387             :   int32_t clockDriftPPM;
     388             :   // average packet waiting time in the jitter buffer (ms)
     389             :   int meanWaitingTimeMs;
     390             :   // median packet waiting time in the jitter buffer (ms)
     391             :   int medianWaitingTimeMs;
     392             :   // min packet waiting time in the jitter buffer (ms)
     393             :   int minWaitingTimeMs;
     394             :   // max packet waiting time in the jitter buffer (ms)
     395             :   int maxWaitingTimeMs;
     396             :   // added samples in off mode due to packet loss
     397             :   size_t addedSamples;
     398             : };
     399             : 
     400             : // Statistics for calls to AudioCodingModule::PlayoutData10Ms().
     401             : struct AudioDecodingCallStats {
     402           0 :   AudioDecodingCallStats()
     403           0 :       : calls_to_silence_generator(0),
     404             :         calls_to_neteq(0),
     405             :         decoded_normal(0),
     406             :         decoded_plc(0),
     407             :         decoded_cng(0),
     408             :         decoded_plc_cng(0),
     409           0 :         decoded_muted_output(0) {}
     410             : 
     411             :   int calls_to_silence_generator;  // Number of calls where silence generated,
     412             :                                    // and NetEq was disengaged from decoding.
     413             :   int calls_to_neteq;              // Number of calls to NetEq.
     414             :   int decoded_normal;  // Number of calls where audio RTP packet decoded.
     415             :   int decoded_plc;     // Number of calls resulted in PLC.
     416             :   int decoded_cng;  // Number of calls where comfort noise generated due to DTX.
     417             :   int decoded_plc_cng;  // Number of calls resulted where PLC faded to CNG.
     418             :   int decoded_muted_output;  // Number of calls returning a muted state output.
     419             : };
     420             : 
     421             : // Type of Noise Suppression.
     422             : enum NsModes {
     423             :   kNsUnchanged = 0,   // previously set mode
     424             :   kNsDefault,         // platform default
     425             :   kNsConference,      // conferencing default
     426             :   kNsLowSuppression,  // lowest suppression
     427             :   kNsModerateSuppression,
     428             :   kNsHighSuppression,
     429             :   kNsVeryHighSuppression  // highest suppression
     430             : };
     431             : 
     432             : // Type of Automatic Gain Control.
     433             : enum AgcModes {
     434             :   kAgcUnchanged = 0,  // previously set mode
     435             :   kAgcDefault,        // platform default
     436             :   // adaptive mode for use when analog volume control exists (e.g. for
     437             :   // PC softphone)
     438             :   kAgcAdaptiveAnalog,
     439             :   // scaling takes place in the digital domain (e.g. for conference servers
     440             :   // and embedded devices)
     441             :   kAgcAdaptiveDigital,
     442             :   // can be used on embedded devices where the capture signal level
     443             :   // is predictable
     444             :   kAgcFixedDigital
     445             : };
     446             : 
     447             : // Type of Echo Control.
     448             : enum EcModes {
     449             :   kEcUnchanged = 0,  // previously set mode
     450             :   kEcDefault,        // platform default
     451             :   kEcConference,     // conferencing default (aggressive AEC)
     452             :   kEcAec,            // Acoustic Echo Cancellation
     453             :   kEcAecm            // AEC mobile
     454             : };
     455             : 
     456             : // Mode of AECM.
     457             : enum AecmModes {
     458             :   kAecmQuietEarpieceOrHeadset = 0,
     459             :   // Quiet earpiece or headset use
     460             :   kAecmEarpiece,         // most earpiece use
     461             :   kAecmLoudEarpiece,     // Loud earpiece or quiet speakerphone use
     462             :   kAecmSpeakerphone,     // most speakerphone use (default)
     463             :   kAecmLoudSpeakerphone  // Loud speakerphone
     464             : };
     465             : 
     466             : // AGC configuration parameters
     467             : struct AgcConfig {
     468             :   unsigned short targetLeveldBOv;
     469             :   unsigned short digitalCompressionGaindB;
     470             :   bool limiterEnable;
     471             : };
     472             : 
     473             : enum StereoChannel { kStereoLeft = 0, kStereoRight, kStereoBoth };
     474             : 
     475             : // Audio device layers
     476             : enum AudioLayers {
     477             :   kAudioPlatformDefault = 0,
     478             :   kAudioWindowsWave = 1,
     479             :   kAudioWindowsCore = 2,
     480             :   kAudioLinuxAlsa = 3,
     481             :   kAudioLinuxPulse = 4,
     482             :   kAudioSndio = 5
     483             : };
     484             : 
     485             : // ==================================================================
     486             : // Video specific types
     487             : // ==================================================================
     488             : 
     489             : // Raw video types
     490             : enum RawVideoType {
     491             :   kVideoI420 = 0,
     492             :   kVideoYV12 = 1,
     493             :   kVideoYUY2 = 2,
     494             :   kVideoUYVY = 3,
     495             :   kVideoIYUV = 4,
     496             :   kVideoARGB = 5,
     497             :   kVideoRGB24 = 6,
     498             :   kVideoRGB565 = 7,
     499             :   kVideoARGB4444 = 8,
     500             :   kVideoARGB1555 = 9,
     501             :   kVideoMJPEG = 10,
     502             :   kVideoNV12 = 11,
     503             :   kVideoNV21 = 12,
     504             :   kVideoBGRA = 13,
     505             :   kVideoUnknown = 99
     506             : };
     507             : 
     508             : enum VideoReceiveState
     509             : {
     510             :   kReceiveStateInitial,            // No video decoded yet
     511             :   kReceiveStateNormal,
     512             :   kReceiveStatePreemptiveNACK,     // NACK sent for missing packet, no decode stall/fail yet
     513             :   kReceiveStateWaitingKey,         // Decoding stalled, waiting for keyframe or NACK
     514             :   kReceiveStateDecodingWithErrors, // Decoding with errors, waiting for keyframe or NACK
     515             :   kReceiveStateNoIncoming          // No errors, but no incoming video since last decode
     516             : };
     517             : 
     518             : // Video codec
     519             : enum { kConfigParameterSize = 128 };
     520             : enum { kPayloadNameSize = 32 };
     521             : enum { kMaxSimulcastStreams = 4 };
     522             : enum { kMaxSpatialLayers = 5 };
     523             : enum { kMaxTemporalStreams = 4 };
     524             : enum { kRIDSize = 32};
     525             : 
     526             : enum VideoCodecComplexity {
     527             :   kComplexityNormal = 0,
     528             :   kComplexityHigh = 1,
     529             :   kComplexityHigher = 2,
     530             :   kComplexityMax = 3
     531             : };
     532             : 
     533             : enum VP8ResilienceMode {
     534             :   kResilienceOff,    // The stream produced by the encoder requires a
     535             :                      // recovery frame (typically a key frame) to be
     536             :                      // decodable after a packet loss.
     537             :   kResilientStream,  // A stream produced by the encoder is resilient to
     538             :                      // packet losses, but packets within a frame subsequent
     539             :                      // to a loss can't be decoded.
     540             :   kResilientFrames   // Same as kResilientStream but with added resilience
     541             :                      // within a frame.
     542             : };
     543             : 
     544             : class TemporalLayersFactory;
     545             : // VP8 specific
     546             : struct VideoCodecVP8 {
     547             :   bool pictureLossIndicationOn;
     548             :   bool feedbackModeOn;
     549             :   VideoCodecComplexity complexity;
     550             :   VP8ResilienceMode resilience;
     551             :   unsigned char numberOfTemporalLayers;
     552             :   bool denoisingOn;
     553             :   bool errorConcealmentOn;
     554             :   bool automaticResizeOn;
     555             :   bool frameDroppingOn;
     556             :   int keyFrameInterval;
     557             :   TemporalLayersFactory* tl_factory;
     558             : };
     559             : 
     560             : // VP9 specific.
     561             : struct VideoCodecVP9 {
     562             :   VideoCodecComplexity complexity;
     563             :   int resilience;
     564             :   unsigned char numberOfTemporalLayers;
     565             :   bool denoisingOn;
     566             :   bool frameDroppingOn;
     567             :   int keyFrameInterval;
     568             :   bool adaptiveQpMode;
     569             :   bool automaticResizeOn;
     570             :   unsigned char numberOfSpatialLayers;
     571             :   bool flexibleMode;
     572             : };
     573             : 
     574             : // TODO(magjed): Move this and other H264 related classes out to their own file.
     575             : namespace H264 {
     576             : 
     577             : enum Profile {
     578             :   kProfileConstrainedBaseline,
     579             :   kProfileBaseline,
     580             :   kProfileMain,
     581             :   kProfileConstrainedHigh,
     582             :   kProfileHigh,
     583             : };
     584             : 
     585             : }  // namespace H264
     586             : 
     587             : // H264 specific.
     588             : struct VideoCodecH264 {
     589             :   bool frameDroppingOn;
     590             :   int keyFrameInterval;
     591             :   double         scaleDownBy;
     592             :   // These are NULL/0 if not externally negotiated.
     593             :   const uint8_t* spsData;
     594             :   size_t spsLen;
     595             :   const uint8_t* ppsData;
     596             :   size_t ppsLen;
     597             :   H264::Profile profile;
     598             :   uint8_t       packetizationMode; // 0 or 1
     599             : };
     600             : 
     601             : // Video codec types
     602             : enum VideoCodecType {
     603             :   kVideoCodecVP8,
     604             :   kVideoCodecVP9,
     605             :   kVideoCodecH264,
     606             :   kVideoCodecI420,
     607             :   kVideoCodecRED,
     608             :   kVideoCodecULPFEC,
     609             :   kVideoCodecFlexfec,
     610             :   kVideoCodecGeneric,
     611             :   kVideoCodecUnknown
     612             : };
     613             : 
     614             : // Translates from name of codec to codec type and vice versa.
     615             : rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type);
     616             : rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name);
     617             : 
     618             : union VideoCodecUnion {
     619             :   VideoCodecVP8 VP8;
     620             :   VideoCodecVP9 VP9;
     621             :   VideoCodecH264 H264;
     622             : };
     623             : 
     624             : // Simulcast is when the same stream is encoded multiple times with different
     625             : // settings such as resolution.
     626             : struct SimulcastStream {
     627             :   unsigned short width;
     628             :   unsigned short height;
     629             :   unsigned char numberOfTemporalLayers;
     630             :   unsigned int maxBitrate;     // kilobits/sec.
     631             :   unsigned int targetBitrate;  // kilobits/sec.
     632             :   unsigned int minBitrate;     // kilobits/sec.
     633             :   unsigned int qpMax;          // minimum quality
     634             :   char         rid[kRIDSize];
     635             :   unsigned int jsMaxBitrate;   // user-controlled max bitrate
     636             :   double       jsScaleDownBy;  // user-controlled downscale
     637             : 
     638             :   bool operator==(const SimulcastStream& other) const {
     639             :     return width == other.width &&
     640             :            height == other.height &&
     641             :            numberOfTemporalLayers == other.numberOfTemporalLayers &&
     642             :            maxBitrate == other.maxBitrate &&
     643             :            targetBitrate == other.targetBitrate &&
     644             :            minBitrate == other.minBitrate &&
     645             :            qpMax == other.qpMax &&
     646             :            strcmp(rid, other.rid) == 0 &&
     647             :            jsMaxBitrate == other.jsMaxBitrate &&
     648             :            jsScaleDownBy == other.jsScaleDownBy;
     649             :   };
     650             : };
     651             : 
     652             : struct SpatialLayer {
     653             :   int scaling_factor_num;
     654             :   int scaling_factor_den;
     655             :   int target_bitrate_bps;
     656             :   // TODO(ivica): Add max_quantizer and min_quantizer?
     657             : };
     658             : 
     659             : enum VideoCodecMode { kRealtimeVideo, kScreensharing };
     660             : 
     661             : // Common video codec properties
     662             : class VideoCodec {
     663             :  public:
     664             :   VideoCodec();
     665             : 
     666             :   // Public variables. TODO(hta): Make them private with accessors.
     667             :   VideoCodecType codecType;
     668             :   char plName[kPayloadNameSize];
     669             :   unsigned char plType;
     670             : 
     671             :   unsigned short width;
     672             :   unsigned short height;
     673             :   // width & height modulo resolution_divisor must be 0
     674             :   unsigned char resolution_divisor;
     675             : 
     676             :   unsigned int startBitrate;   // kilobits/sec.
     677             :   unsigned int maxBitrate;     // kilobits/sec.
     678             :   unsigned int minBitrate;     // kilobits/sec.
     679             :   unsigned int targetBitrate;  // kilobits/sec.
     680             : 
     681             :   unsigned char maxFramerate;
     682             : 
     683             :   unsigned int qpMax;
     684             :   unsigned char numberOfSimulcastStreams;
     685             :   unsigned char ridId;
     686             :   SimulcastStream simulcastStream[kMaxSimulcastStreams];
     687             :   SpatialLayer spatialLayers[kMaxSpatialLayers];
     688             : 
     689             :   VideoCodecMode mode;
     690             :   bool expect_encode_from_texture;
     691             : 
     692             :   bool operator==(const VideoCodec& other) const = delete;
     693             :   bool operator!=(const VideoCodec& other) const = delete;
     694             : 
     695             :   // Accessors for codec specific information.
     696             :   // There is a const version of each that returns a reference,
     697             :   // and a non-const version that returns a pointer, in order
     698             :   // to allow modification of the parameters.
     699             :   VideoCodecVP8* VP8();
     700             :   const VideoCodecVP8& VP8() const;
     701             :   VideoCodecVP9* VP9();
     702             :   const VideoCodecVP9& VP9() const;
     703             :   VideoCodecH264* H264();
     704             :   const VideoCodecH264& H264() const;
     705             : 
     706             :  private:
     707             :   // TODO(hta): Consider replacing the union with a pointer type.
     708             :   // This will allow removing the VideoCodec* types from this file.
     709             :   VideoCodecUnion codec_specific_;
     710             : };
     711             : 
     712             : class BitrateAllocation {
     713             :  public:
     714             :   static const uint32_t kMaxBitrateBps;
     715             :   BitrateAllocation();
     716             : 
     717             :   bool SetBitrate(size_t spatial_index,
     718             :                   size_t temporal_index,
     719             :                   uint32_t bitrate_bps);
     720             : 
     721             :   uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
     722             : 
     723             :   // Get the sum of all the temporal layer for a specific spatial layer.
     724             :   uint32_t GetSpatialLayerSum(size_t spatial_index) const;
     725             : 
     726           0 :   uint32_t get_sum_bps() const { return sum_; }  // Sum of all bitrates.
     727           0 :   uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
     728             : 
     729           0 :   inline bool operator==(const BitrateAllocation& other) const {
     730           0 :     return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
     731             :   }
     732           0 :   inline bool operator!=(const BitrateAllocation& other) const {
     733           0 :     return !(*this == other);
     734             :   }
     735             : 
     736             :  private:
     737             :   uint32_t sum_;
     738             :   uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
     739             : };
     740             : 
     741             : // Bandwidth over-use detector options.  These are used to drive
     742             : // experimentation with bandwidth estimation parameters.
     743             : // See modules/remote_bitrate_estimator/overuse_detector.h
     744             : // TODO(terelius): This is only used in overuse_estimator.cc, and only in the
     745             : // default constructed state. Can we move the relevant variables into that
     746             : // class and delete this? See also disabled warning at line 27
     747             : struct OverUseDetectorOptions {
     748           0 :   OverUseDetectorOptions()
     749           0 :       : initial_slope(8.0 / 512.0),
     750             :         initial_offset(0),
     751             :         initial_e(),
     752             :         initial_process_noise(),
     753             :         initial_avg_noise(0.0),
     754           0 :         initial_var_noise(50) {
     755           0 :     initial_e[0][0] = 100;
     756           0 :     initial_e[1][1] = 1e-1;
     757           0 :     initial_e[0][1] = initial_e[1][0] = 0;
     758           0 :     initial_process_noise[0] = 1e-13;
     759           0 :     initial_process_noise[1] = 1e-3;
     760           0 :   }
     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             : enum CPULoadState {
     770             :   kLoadRelaxed = 0,
     771             :   kLoadNormal,
     772             :   kLoadStressed,
     773             :   kLoadLast,
     774             : };
     775             : 
     776           0 : class CPULoadStateObserver {
     777             : public:
     778             :   virtual void onLoadStateChanged(CPULoadState aNewState) = 0;
     779           0 :   virtual ~CPULoadStateObserver() {};
     780             : };
     781             : 
     782             : class CPULoadStateCallbackInvoker {
     783             : public:
     784             :     virtual void AddObserver(CPULoadStateObserver* aObserver) = 0;
     785             :     virtual void RemoveObserver(CPULoadStateObserver* aObserver) = 0;
     786             :     virtual ~CPULoadStateCallbackInvoker() {};
     787             : };
     788             : 
     789             : // This structure will have the information about when packet is actually
     790             : // received by socket.
     791             : struct PacketTime {
     792           0 :   PacketTime() : timestamp(-1), not_before(-1) {}
     793             :   PacketTime(int64_t timestamp, int64_t not_before)
     794             :       : timestamp(timestamp), not_before(not_before) {}
     795             : 
     796             :   int64_t timestamp;   // Receive time after socket delivers the data.
     797             :   int64_t not_before;  // Earliest possible time the data could have arrived,
     798             :                        // indicating the potential error in the |timestamp|
     799             :                        // value,in case the system is busy.
     800             :                        // For example, the time of the last select() call.
     801             :                        // If unknown, this value will be set to zero.
     802             : };
     803             : 
     804             : // Minimum and maximum playout delay values from capture to render.
     805             : // These are best effort values.
     806             : //
     807             : // A value < 0 indicates no change from previous valid value.
     808             : //
     809             : // min = max = 0 indicates that the receiver should try and render
     810             : // frame as soon as possible.
     811             : //
     812             : // min = x, max = y indicates that the receiver is free to adapt
     813             : // in the range (x, y) based on network jitter.
     814             : //
     815             : // Note: Given that this gets embedded in a union, it is up-to the owner to
     816             : // initialize these values.
     817             : struct PlayoutDelay {
     818             :   int min_ms;
     819             :   int max_ms;
     820             : };
     821             : 
     822           0 : struct RTPHeaderExtension {
     823             :   RTPHeaderExtension();
     824             :   RTPHeaderExtension(const RTPHeaderExtension& rhs);
     825             :   RTPHeaderExtension& operator=(const RTPHeaderExtension& rhs);
     826             : 
     827             :   bool hasTransmissionTimeOffset;
     828             :   int32_t transmissionTimeOffset;
     829             :   bool hasAbsoluteSendTime;
     830             :   uint32_t absoluteSendTime;
     831             :   bool hasTransportSequenceNumber;
     832             :   uint16_t transportSequenceNumber;
     833             : 
     834             :   // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
     835             :   // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
     836             :   bool hasAudioLevel;
     837             :   bool voiceActivity;
     838             :   uint8_t audioLevel;
     839             : 
     840             :   // For Coordination of Video Orientation. See
     841             :   // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
     842             :   // ts_126114v120700p.pdf
     843             :   bool hasVideoRotation;
     844             :   VideoRotation videoRotation;
     845             : 
     846             :   PlayoutDelay playout_delay = {-1, -1};
     847             : 
     848             :   // RID values for simulcast; see draft-roach-avtext-rid
     849             :   bool hasRID;
     850             :   std::unique_ptr<char[]> rid; // UTF8 string
     851             : };
     852             : 
     853           0 : struct RTPHeader {
     854             :   RTPHeader();
     855             : 
     856             :   bool markerBit;
     857             :   uint8_t payloadType;
     858             :   uint16_t sequenceNumber;
     859             :   uint32_t timestamp;
     860             :   uint32_t ssrc;
     861             :   uint8_t numCSRCs;
     862             :   uint32_t arrOfCSRCs[kRtpCsrcSize];
     863             :   size_t paddingLength;
     864             :   size_t headerLength;
     865             :   int payload_type_frequency;
     866             :   RTPHeaderExtension extension;
     867             : };
     868             : 
     869             : struct RtpPacketCounter {
     870           0 :   RtpPacketCounter()
     871           0 :       : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
     872             : 
     873           0 :   void Add(const RtpPacketCounter& other) {
     874           0 :     header_bytes += other.header_bytes;
     875           0 :     payload_bytes += other.payload_bytes;
     876           0 :     padding_bytes += other.padding_bytes;
     877           0 :     packets += other.packets;
     878           0 :   }
     879             : 
     880           0 :   void Subtract(const RtpPacketCounter& other) {
     881           0 :     RTC_DCHECK_GE(header_bytes, other.header_bytes);
     882           0 :     header_bytes -= other.header_bytes;
     883           0 :     RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
     884           0 :     payload_bytes -= other.payload_bytes;
     885           0 :     RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
     886           0 :     padding_bytes -= other.padding_bytes;
     887           0 :     RTC_DCHECK_GE(packets, other.packets);
     888           0 :     packets -= other.packets;
     889           0 :   }
     890             : 
     891           0 :   void AddPacket(size_t packet_length, const RTPHeader& header) {
     892           0 :     ++packets;
     893           0 :     header_bytes += header.headerLength;
     894           0 :     padding_bytes += header.paddingLength;
     895           0 :     payload_bytes +=
     896           0 :         packet_length - (header.headerLength + header.paddingLength);
     897           0 :   }
     898             : 
     899           0 :   size_t TotalBytes() const {
     900           0 :     return header_bytes + payload_bytes + padding_bytes;
     901             :   }
     902             : 
     903             :   size_t header_bytes;   // Number of bytes used by RTP headers.
     904             :   size_t payload_bytes;  // Payload bytes, excluding RTP headers and padding.
     905             :   size_t padding_bytes;  // Number of padding bytes.
     906             :   uint32_t packets;      // Number of packets.
     907             : };
     908             : 
     909             : // Data usage statistics for a (rtp) stream.
     910             : struct StreamDataCounters {
     911             :   StreamDataCounters();
     912             : 
     913           0 :   void Add(const StreamDataCounters& other) {
     914           0 :     transmitted.Add(other.transmitted);
     915           0 :     retransmitted.Add(other.retransmitted);
     916           0 :     fec.Add(other.fec);
     917           0 :     if (other.first_packet_time_ms != -1 &&
     918           0 :         (other.first_packet_time_ms < first_packet_time_ms ||
     919           0 :          first_packet_time_ms == -1)) {
     920             :       // Use oldest time.
     921           0 :       first_packet_time_ms = other.first_packet_time_ms;
     922             :     }
     923           0 :   }
     924             : 
     925           0 :   void Subtract(const StreamDataCounters& other) {
     926           0 :     transmitted.Subtract(other.transmitted);
     927           0 :     retransmitted.Subtract(other.retransmitted);
     928           0 :     fec.Subtract(other.fec);
     929           0 :     if (other.first_packet_time_ms != -1 &&
     930           0 :         (other.first_packet_time_ms > first_packet_time_ms ||
     931           0 :          first_packet_time_ms == -1)) {
     932             :       // Use youngest time.
     933           0 :       first_packet_time_ms = other.first_packet_time_ms;
     934             :     }
     935           0 :   }
     936             : 
     937           0 :   int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
     938           0 :     return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
     939             :   }
     940             : 
     941             :   // Returns the number of bytes corresponding to the actual media payload (i.e.
     942             :   // RTP headers, padding, retransmissions and fec packets are excluded).
     943             :   // Note this function does not have meaning for an RTX stream.
     944           0 :   size_t MediaPayloadBytes() const {
     945           0 :     return transmitted.payload_bytes - retransmitted.payload_bytes -
     946           0 :            fec.payload_bytes;
     947             :   }
     948             : 
     949             :   int64_t first_packet_time_ms;    // Time when first packet is sent/received.
     950             :   RtpPacketCounter transmitted;    // Number of transmitted packets/bytes.
     951             :   RtpPacketCounter retransmitted;  // Number of retransmitted packets/bytes.
     952             :   RtpPacketCounter fec;            // Number of redundancy packets/bytes.
     953             : };
     954             : 
     955             : // Callback, called whenever byte/packet counts have been updated.
     956           0 : class StreamDataCountersCallback {
     957             :  public:
     958           0 :   virtual ~StreamDataCountersCallback() {}
     959             : 
     960             :   virtual void DataCountersUpdated(const StreamDataCounters& counters,
     961             :                                    uint32_t ssrc) = 0;
     962             : };
     963             : 
     964             : // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
     965             : // RTCP mode is described by RFC 5506.
     966             : enum class RtcpMode { kOff, kCompound, kReducedSize };
     967             : 
     968             : enum NetworkState {
     969             :   kNetworkUp,
     970             :   kNetworkDown,
     971             : };
     972             : 
     973             : }  // namespace webrtc
     974             : 
     975             : #endif  // WEBRTC_COMMON_TYPES_H_

Generated by: LCOV version 1.13