blob: db6f0ccf1faab0ba831a8fe8243e64a3174e02f1 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
phoglund@webrtc.org8bfee842012-02-17 09:32:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef COMMON_TYPES_H_
12#define COMMON_TYPES_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000014#include <stddef.h>
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000015#include <string.h>
kwiberg5bf4e082016-12-19 06:04:04 -080016#include <ostream>
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000017#include <string>
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000018#include <vector>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/array_view.h"
21#include "api/optional.h"
22#include "api/video/video_content_type.h"
23#include "api/video/video_rotation.h"
24#include "api/video/video_timing.h"
25#include "rtc_base/checks.h"
26#include "rtc_base/deprecation.h"
27#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000028
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000029#if defined(_MSC_VER)
30// Disable "new behavior: elements of array will be default initialized"
31// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070032#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000033#endif
34
kwiberg77eab702016-09-28 17:42:01 -070035#if defined(WEBRTC_EXPORT)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000036#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg77eab702016-09-28 17:42:01 -070037#elif defined(WEBRTC_DLL)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000038#define WEBRTC_DLLEXPORT _declspec(dllimport)
niklase@google.com470e71d2011-07-07 08:21:25 +000039#else
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000040#define WEBRTC_DLLEXPORT
niklase@google.com470e71d2011-07-07 08:21:25 +000041#endif
42
43#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000044#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:25 +000045#endif
46
Peter Boström8b79b072016-02-26 16:31:37 +010047#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000048
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000049#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +000050// Compares two strings without regard to case.
51#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
52// Compares characters of two strings without regard to case.
53#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
54#else
55#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
56#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
57#endif
58
niklase@google.com470e71d2011-07-07 08:21:25 +000059namespace webrtc {
60
tommia6219cc2016-06-15 10:30:14 -070061class RewindableStream {
62 public:
63 virtual ~RewindableStream() {}
64 virtual int Rewind() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000065};
66
tommia6219cc2016-06-15 10:30:14 -070067class InStream : public RewindableStream {
68 public:
69 // Reads |len| bytes from file to |buf|. Returns the number of bytes read
70 // or -1 on error.
71 virtual int Read(void* buf, size_t len) = 0;
72};
73
74class OutStream : public RewindableStream {
75 public:
76 // Writes |len| bytes from |buf| to file. The actual writing may happen
77 // some time later. Call Flush() to force a write.
78 virtual bool Write(const void* buf, size_t len) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000079};
80
solenberg634b86e2016-09-01 07:54:53 -070081enum TraceModule {
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,
niklase@google.com470e71d2011-07-07 08:21:25 +0000103};
104
solenberg634b86e2016-09-01 07:54:53 -0700105enum TraceLevel {
106 kTraceNone = 0x0000, // no trace
107 kTraceStateInfo = 0x0001,
108 kTraceWarning = 0x0002,
109 kTraceError = 0x0004,
110 kTraceCritical = 0x0008,
111 kTraceApiCall = 0x0010,
112 kTraceDefault = 0x00ff,
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
solenberg634b86e2016-09-01 07:54:53 -0700114 kTraceModuleCall = 0x0020,
115 kTraceMemory = 0x0100, // memory info
116 kTraceTimer = 0x0200, // timing info
117 kTraceStream = 0x0400, // "continuous" stream of data
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
solenberg634b86e2016-09-01 07:54:53 -0700119 // used for debug purposes
120 kTraceDebug = 0x0800, // debug
121 kTraceInfo = 0x1000, // debug info
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
solenberg634b86e2016-09-01 07:54:53 -0700123 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
124 kTraceTerseInfo = 0x2000,
andrew@webrtc.org655d8f52012-11-20 07:34:45 +0000125
solenberg634b86e2016-09-01 07:54:53 -0700126 kTraceAll = 0xffff
niklase@google.com470e71d2011-07-07 08:21:25 +0000127};
128
129// External Trace API
andrew@webrtc.org23ec30b2012-11-15 05:33:25 +0000130class TraceCallback {
131 public:
132 virtual void Print(TraceLevel level, const char* message, int length) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
andrew@webrtc.org23ec30b2012-11-15 05:33:25 +0000134 protected:
135 virtual ~TraceCallback() {}
136 TraceCallback() {}
137};
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
solenberg634b86e2016-09-01 07:54:53 -0700139enum FileFormats {
140 kFileFormatWavFile = 1,
141 kFileFormatCompressedFile = 2,
142 kFileFormatPreencodedFile = 4,
143 kFileFormatPcm16kHzFile = 7,
144 kFileFormatPcm8kHzFile = 8,
Minyue Li85a3b6b2017-09-01 14:36:33 +0200145 kFileFormatPcm32kHzFile = 9,
146 kFileFormatPcm48kHzFile = 10
niklase@google.com470e71d2011-07-07 08:21:25 +0000147};
148
pbos22993e12015-10-19 02:39:06 -0700149enum FrameType {
150 kEmptyFrame = 0,
151 kAudioFrameSpeech = 1,
152 kAudioFrameCN = 2,
153 kVideoFrameKey = 3,
154 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000155};
156
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000157// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000158struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000159 RtcpStatistics()
solenberg634b86e2016-09-01 07:54:53 -0700160 : fraction_lost(0),
srte186d9c32017-08-04 05:03:53 -0700161 packets_lost(0),
162 extended_highest_sequence_number(0),
solenberg634b86e2016-09-01 07:54:53 -0700163 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000164
165 uint8_t fraction_lost;
srte186d9c32017-08-04 05:03:53 -0700166 union {
167 uint32_t packets_lost;
168 RTC_DEPRECATED uint32_t cumulative_lost;
169 };
170 union {
171 uint32_t extended_highest_sequence_number;
172 RTC_DEPRECATED uint32_t extended_max_sequence_number;
173 };
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000174 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000175};
176
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000177class RtcpStatisticsCallback {
178 public:
179 virtual ~RtcpStatisticsCallback() {}
180
181 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
182 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000183 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000184};
185
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000186// Statistics for RTCP packet types.
187struct RtcpPacketTypeCounter {
188 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -0700189 : first_packet_time_ms(-1),
190 nack_packets(0),
191 fir_packets(0),
192 pli_packets(0),
193 nack_requests(0),
194 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000195
196 void Add(const RtcpPacketTypeCounter& other) {
197 nack_packets += other.nack_packets;
198 fir_packets += other.fir_packets;
199 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000200 nack_requests += other.nack_requests;
201 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000202 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -0700203 (other.first_packet_time_ms < first_packet_time_ms ||
204 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000205 // Use oldest time.
206 first_packet_time_ms = other.first_packet_time_ms;
207 }
208 }
209
sprang07fb9be2016-02-24 07:55:00 -0800210 void Subtract(const RtcpPacketTypeCounter& other) {
211 nack_packets -= other.nack_packets;
212 fir_packets -= other.fir_packets;
213 pli_packets -= other.pli_packets;
214 nack_requests -= other.nack_requests;
215 unique_nack_requests -= other.unique_nack_requests;
216 if (other.first_packet_time_ms != -1 &&
217 (other.first_packet_time_ms > first_packet_time_ms ||
218 first_packet_time_ms == -1)) {
219 // Use youngest time.
220 first_packet_time_ms = other.first_packet_time_ms;
221 }
222 }
223
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000224 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
225 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000226 }
227
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000228 int UniqueNackRequestsInPercent() const {
229 if (nack_requests == 0) {
230 return 0;
231 }
solenberg634b86e2016-09-01 07:54:53 -0700232 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
233 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000234 }
235
solenberg634b86e2016-09-01 07:54:53 -0700236 int64_t first_packet_time_ms; // Time when first packet is sent/received.
237 uint32_t nack_packets; // Number of RTCP NACK packets.
238 uint32_t fir_packets; // Number of RTCP FIR packets.
239 uint32_t pli_packets; // Number of RTCP PLI packets.
240 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000241 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000242};
243
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000244class RtcpPacketTypeCounterObserver {
245 public:
246 virtual ~RtcpPacketTypeCounterObserver() {}
247 virtual void RtcpPacketTypesCounterUpdated(
248 uint32_t ssrc,
249 const RtcpPacketTypeCounter& packet_counter) = 0;
250};
251
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000252// Rate statistics for a stream.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000253struct BitrateStatistics {
sprangcd349d92016-07-13 09:11:28 -0700254 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000255
solenberg634b86e2016-09-01 07:54:53 -0700256 uint32_t bitrate_bps; // Bitrate in bits per second.
257 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000258};
259
260// Callback, used to notify an observer whenever new rates have been estimated.
261class BitrateStatisticsObserver {
262 public:
263 virtual ~BitrateStatisticsObserver() {}
264
sprangcd349d92016-07-13 09:11:28 -0700265 virtual void Notify(uint32_t total_bitrate_bps,
266 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000267 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000268};
269
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000270struct FrameCounts {
271 FrameCounts() : key_frames(0), delta_frames(0) {}
272 int key_frames;
273 int delta_frames;
274};
275
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000276// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000277class FrameCountObserver {
278 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000279 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000280 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
281 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000282};
283
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000284// Callback, used to notify an observer whenever the send-side delay is updated.
285class SendSideDelayObserver {
286 public:
287 virtual ~SendSideDelayObserver() {}
288 virtual void SendSideDelayUpdated(int avg_delay_ms,
289 int max_delay_ms,
290 uint32_t ssrc) = 0;
291};
292
asapersson35151f32016-05-02 23:44:01 -0700293// Callback, used to notify an observer whenever a packet is sent to the
294// transport.
295// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
296// Remove SendSideDelayObserver once possible.
297class SendPacketObserver {
298 public:
299 virtual ~SendPacketObserver() {}
300 virtual void OnSendPacket(uint16_t packet_id,
301 int64_t capture_time_ms,
302 uint32_t ssrc) = 0;
303};
304
michaelt4da30442016-11-17 01:38:43 -0800305// Callback, used to notify an observer when the overhead per packet
306// has changed.
307class OverheadObserver {
308 public:
309 virtual ~OverheadObserver() = default;
310 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
311};
312
niklase@google.com470e71d2011-07-07 08:21:25 +0000313// ==================================================================
314// Voice specific types
315// ==================================================================
316
317// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000318struct CodecInst {
319 int pltype;
320 char plname[RTP_PAYLOAD_NAME_SIZE];
321 int plfreq;
322 int pacsize;
Peter Kasting69558702016-01-12 16:26:35 -0800323 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000324 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
325
326 bool operator==(const CodecInst& other) const {
327 return pltype == other.pltype &&
328 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenberg634b86e2016-09-01 07:54:53 -0700329 plfreq == other.plfreq && pacsize == other.pacsize &&
330 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000331 }
332
solenberg634b86e2016-09-01 07:54:53 -0700333 bool operator!=(const CodecInst& other) const { return !(*this == other); }
kwiberg5bf4e082016-12-19 06:04:04 -0800334
335 friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
336 os << "{pltype: " << ci.pltype;
337 os << ", plname: " << ci.plname;
338 os << ", plfreq: " << ci.plfreq;
339 os << ", pacsize: " << ci.pacsize;
340 os << ", channels: " << ci.channels;
341 os << ", rate: " << ci.rate << "}";
342 return os;
343 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000344};
345
niklase@google.com470e71d2011-07-07 08:21:25 +0000346// RTP
solenberg634b86e2016-09-01 07:54:53 -0700347enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
solenberg634b86e2016-09-01 07:54:53 -0700349enum PayloadFrequencies {
350 kFreq8000Hz = 8000,
351 kFreq16000Hz = 16000,
352 kFreq32000Hz = 32000
niklase@google.com470e71d2011-07-07 08:21:25 +0000353};
354
solenberg634b86e2016-09-01 07:54:53 -0700355// Degree of bandwidth reduction.
356enum VadModes {
357 kVadConventional = 0, // lowest reduction
358 kVadAggressiveLow,
359 kVadAggressiveMid,
360 kVadAggressiveHigh // highest reduction
niklase@google.com470e71d2011-07-07 08:21:25 +0000361};
362
solenberg634b86e2016-09-01 07:54:53 -0700363// NETEQ statistics.
364struct NetworkStatistics {
365 // current jitter buffer size in ms
366 uint16_t currentBufferSize;
367 // preferred (optimal) buffer size in ms
368 uint16_t preferredBufferSize;
369 // adding extra delay due to "peaky jitter"
370 bool jitterPeaksFound;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700371 // Total number of audio samples received, including synthesized samples.
372 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalsamplesreceived
373 uint64_t totalSamplesReceived;
374 // Total number of inbound audio samples that are based on synthesized data to
375 // conceal packet loss.
376 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-concealedsamples
377 uint64_t concealedSamples;
solenberg634b86e2016-09-01 07:54:53 -0700378 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
379 uint16_t currentPacketLossRate;
380 // Late loss rate; fraction between 0 and 1, scaled to Q14.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200381 union {
382 RTC_DEPRECATED uint16_t currentDiscardRate;
383 };
solenberg634b86e2016-09-01 07:54:53 -0700384 // fraction (of original stream) of synthesized audio inserted through
385 // expansion (in Q14)
386 uint16_t currentExpandRate;
387 // fraction (of original stream) of synthesized speech inserted through
388 // expansion (in Q14)
389 uint16_t currentSpeechExpandRate;
390 // fraction of synthesized speech inserted through pre-emptive expansion
391 // (in Q14)
392 uint16_t currentPreemptiveRate;
393 // fraction of data removed through acceleration (in Q14)
394 uint16_t currentAccelerateRate;
395 // fraction of data coming from secondary decoding (in Q14)
396 uint16_t currentSecondaryDecodedRate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200397 // Fraction of secondary data, including FEC and RED, that is discarded (in
398 // Q14). Discarding of secondary data can be caused by the reception of the
399 // primary data, obsoleting the secondary data. It can also be caused by early
400 // or late arrival of secondary data.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200401 uint16_t currentSecondaryDiscardedRate;
solenberg634b86e2016-09-01 07:54:53 -0700402 // clock-drift in parts-per-million (negative or positive)
403 int32_t clockDriftPPM;
404 // average packet waiting time in the jitter buffer (ms)
405 int meanWaitingTimeMs;
406 // median packet waiting time in the jitter buffer (ms)
407 int medianWaitingTimeMs;
408 // min packet waiting time in the jitter buffer (ms)
409 int minWaitingTimeMs;
410 // max packet waiting time in the jitter buffer (ms)
411 int maxWaitingTimeMs;
412 // added samples in off mode due to packet loss
413 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414};
415
wu@webrtc.org24301a62013-12-13 19:17:43 +0000416// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
417struct AudioDecodingCallStats {
418 AudioDecodingCallStats()
419 : calls_to_silence_generator(0),
420 calls_to_neteq(0),
421 decoded_normal(0),
422 decoded_plc(0),
423 decoded_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700424 decoded_plc_cng(0),
425 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43 +0000426
427 int calls_to_silence_generator; // Number of calls where silence generated,
428 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 07:54:53 -0700429 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000430 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 07:54:53 -0700431 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000432 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
433 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 01:47:12 -0700434 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000435};
436
niklase@google.com470e71d2011-07-07 08:21:25 +0000437// ==================================================================
438// Video specific types
439// ==================================================================
440
nisseeb44b392017-04-28 07:18:05 -0700441// TODO(nisse): Delete, and switch to fourcc values everywhere?
442// Supported video types.
443enum class VideoType {
444 kUnknown,
445 kI420,
446 kIYUV,
447 kRGB24,
448 kABGR,
449 kARGB,
450 kARGB4444,
451 kRGB565,
452 kARGB1555,
453 kYUY2,
454 kYV12,
455 kUYVY,
456 kMJPEG,
457 kNV21,
458 kNV12,
459 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25 +0000460};
461
462// Video codec
solenberg634b86e2016-09-01 07:54:53 -0700463enum { kPayloadNameSize = 32 };
464enum { kMaxSimulcastStreams = 4 };
sprangce4aef12015-11-02 07:23:20 -0800465enum { kMaxSpatialLayers = 5 };
solenberg634b86e2016-09-01 07:54:53 -0700466enum { kMaxTemporalStreams = 4 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000467
solenberg634b86e2016-09-01 07:54:53 -0700468enum VideoCodecComplexity {
469 kComplexityNormal = 0,
470 kComplexityHigh = 1,
471 kComplexityHigher = 2,
472 kComplexityMax = 3
niklase@google.com470e71d2011-07-07 08:21:25 +0000473};
474
stefan@webrtc.orgefd0a482011-12-29 10:12:35 +0000475enum VP8ResilienceMode {
476 kResilienceOff, // The stream produced by the encoder requires a
477 // recovery frame (typically a key frame) to be
478 // decodable after a packet loss.
479 kResilientStream, // A stream produced by the encoder is resilient to
480 // packet losses, but packets within a frame subsequent
481 // to a loss can't be decoded.
482 kResilientFrames // Same as kResilientStream but with added resilience
483 // within a frame.
484};
485
Peter Boström7b971e72016-01-19 16:26:16 +0100486class TemporalLayersFactory;
niklase@google.com470e71d2011-07-07 08:21:25 +0000487// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000488struct VideoCodecVP8 {
nisse3257b162017-03-21 01:54:13 -0700489 // TODO(nisse): Unused, delete?
solenberg634b86e2016-09-01 07:54:53 -0700490 bool pictureLossIndicationOn;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000491 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 07:54:53 -0700492 VP8ResilienceMode resilience;
493 unsigned char numberOfTemporalLayers;
494 bool denoisingOn;
495 bool errorConcealmentOn;
496 bool automaticResizeOn;
497 bool frameDroppingOn;
498 int keyFrameInterval;
Erik Språng08127a92016-11-16 16:41:30 +0100499 TemporalLayersFactory* tl_factory;
niklase@google.com470e71d2011-07-07 08:21:25 +0000500};
501
asaperssona9455ab2015-07-31 06:10:09 -0700502// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000503struct VideoCodecVP9 {
504 VideoCodecComplexity complexity;
asapersson15dcb382017-06-08 02:55:08 -0700505 bool resilienceOn;
solenberg634b86e2016-09-01 07:54:53 -0700506 unsigned char numberOfTemporalLayers;
507 bool denoisingOn;
508 bool frameDroppingOn;
509 int keyFrameInterval;
510 bool adaptiveQpMode;
511 bool automaticResizeOn;
512 unsigned char numberOfSpatialLayers;
513 bool flexibleMode;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000514};
515
magjede69a1a92016-11-25 10:06:31 -0800516// TODO(magjed): Move this and other H264 related classes out to their own file.
517namespace H264 {
518
519enum Profile {
520 kProfileConstrainedBaseline,
521 kProfileBaseline,
522 kProfileMain,
523 kProfileConstrainedHigh,
524 kProfileHigh,
525};
526
527} // namespace H264
528
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000529// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000530struct VideoCodecH264 {
solenberg634b86e2016-09-01 07:54:53 -0700531 bool frameDroppingOn;
532 int keyFrameInterval;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000533 // These are NULL/0 if not externally negotiated.
534 const uint8_t* spsData;
solenberg634b86e2016-09-01 07:54:53 -0700535 size_t spsLen;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000536 const uint8_t* ppsData;
solenberg634b86e2016-09-01 07:54:53 -0700537 size_t ppsLen;
magjede69a1a92016-11-25 10:06:31 -0800538 H264::Profile profile;
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000539};
540
niklase@google.com470e71d2011-07-07 08:21:25 +0000541// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000542enum VideoCodecType {
543 kVideoCodecVP8,
544 kVideoCodecVP9,
545 kVideoCodecH264,
546 kVideoCodecI420,
547 kVideoCodecRED,
548 kVideoCodecULPFEC,
brandtr87d7d772016-11-07 03:03:41 -0800549 kVideoCodecFlexfec,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000550 kVideoCodecGeneric,
551 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25 +0000552};
553
Erik Språng08127a92016-11-16 16:41:30 +0100554// Translates from name of codec to codec type and vice versa.
kthelgason1cdddc92017-08-24 03:52:48 -0700555const char* CodecTypeToPayloadString(VideoCodecType type);
556VideoCodecType PayloadStringToCodecType(const std::string& name);
Erik Språng08127a92016-11-16 16:41:30 +0100557
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000558union VideoCodecUnion {
solenberg634b86e2016-09-01 07:54:53 -0700559 VideoCodecVP8 VP8;
560 VideoCodecVP9 VP9;
561 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25 +0000562};
563
phoglund@webrtc.org8bfee842012-02-17 09:32:48 +0000564// Simulcast is when the same stream is encoded multiple times with different
565// settings such as resolution.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000566struct SimulcastStream {
solenberg634b86e2016-09-01 07:54:53 -0700567 unsigned short width;
568 unsigned short height;
569 unsigned char numberOfTemporalLayers;
570 unsigned int maxBitrate; // kilobits/sec.
571 unsigned int targetBitrate; // kilobits/sec.
572 unsigned int minBitrate; // kilobits/sec.
573 unsigned int qpMax; // minimum quality
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000574};
575
sprangce4aef12015-11-02 07:23:20 -0800576struct SpatialLayer {
577 int scaling_factor_num;
578 int scaling_factor_den;
579 int target_bitrate_bps;
580 // TODO(ivica): Add max_quantizer and min_quantizer?
581};
582
solenberg634b86e2016-09-01 07:54:53 -0700583enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000584
niklase@google.com470e71d2011-07-07 08:21:25 +0000585// Common video codec properties
hta257dc392016-10-25 09:05:06 -0700586class VideoCodec {
587 public:
588 VideoCodec();
589
590 // Public variables. TODO(hta): Make them private with accessors.
solenberg634b86e2016-09-01 07:54:53 -0700591 VideoCodecType codecType;
592 char plName[kPayloadNameSize];
593 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000594
solenberg634b86e2016-09-01 07:54:53 -0700595 unsigned short width;
596 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25 +0000597
solenberg634b86e2016-09-01 07:54:53 -0700598 unsigned int startBitrate; // kilobits/sec.
599 unsigned int maxBitrate; // kilobits/sec.
600 unsigned int minBitrate; // kilobits/sec.
601 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52 +0000602
Stefan Holmer144475b2017-03-10 15:08:26 +0100603 uint32_t maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000604
solenberg634b86e2016-09-01 07:54:53 -0700605 unsigned int qpMax;
606 unsigned char numberOfSimulcastStreams;
607 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 07:23:20 -0800608 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000609
solenberg634b86e2016-09-01 07:54:53 -0700610 VideoCodecMode mode;
611 bool expect_encode_from_texture;
andresp@webrtc.org185bae42013-05-14 08:02:25 +0000612
ilnik04f4d122017-06-19 07:18:55 -0700613 // Timing frames configuration. There is delay of delay_ms between two
614 // consequent timing frames, excluding outliers. Frame is always made a
615 // timing frame if it's at least outlier_ratio in percent of "ideal" average
616 // frame given bitrate and framerate, i.e. if it's bigger than
617 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
618 // frames will not be sent too often usually. Yet large frames will always
619 // have timing information for debug purposes because they are more likely to
620 // cause extra delays.
621 struct TimingFrameTriggerThresholds {
622 int64_t delay_ms;
623 uint16_t outlier_ratio_percent;
624 } timing_frame_thresholds;
625
Peter Boström7b971e72016-01-19 16:26:16 +0100626 bool operator==(const VideoCodec& other) const = delete;
627 bool operator!=(const VideoCodec& other) const = delete;
hta257dc392016-10-25 09:05:06 -0700628
629 // Accessors for codec specific information.
630 // There is a const version of each that returns a reference,
631 // and a non-const version that returns a pointer, in order
632 // to allow modification of the parameters.
633 VideoCodecVP8* VP8();
634 const VideoCodecVP8& VP8() const;
635 VideoCodecVP9* VP9();
636 const VideoCodecVP9& VP9() const;
637 VideoCodecH264* H264();
638 const VideoCodecH264& H264() const;
639
hta527d3472016-11-16 23:23:04 -0800640 private:
hta257dc392016-10-25 09:05:06 -0700641 // TODO(hta): Consider replacing the union with a pointer type.
642 // This will allow removing the VideoCodec* types from this file.
hta527d3472016-11-16 23:23:04 -0800643 VideoCodecUnion codec_specific_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000644};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000645
Erik Språng08127a92016-11-16 16:41:30 +0100646class BitrateAllocation {
647 public:
648 static const uint32_t kMaxBitrateBps;
649 BitrateAllocation();
650
651 bool SetBitrate(size_t spatial_index,
652 size_t temporal_index,
653 uint32_t bitrate_bps);
654
655 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
656
657 // Get the sum of all the temporal layer for a specific spatial layer.
658 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
659
660 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
661 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
662
663 inline bool operator==(const BitrateAllocation& other) const {
664 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
665 }
666 inline bool operator!=(const BitrateAllocation& other) const {
667 return !(*this == other);
668 }
669
sprangd0fc37a2017-06-22 05:40:25 -0700670 // Expensive, please use only in tests.
671 std::string ToString() const;
672 std::ostream& operator<<(std::ostream& os) const;
673
Erik Språng08127a92016-11-16 16:41:30 +0100674 private:
675 uint32_t sum_;
676 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
677};
678
stefan64c0a0a2015-11-27 01:02:31 -0800679// Bandwidth over-use detector options. These are used to drive
680// experimentation with bandwidth estimation parameters.
681// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800682// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
683// default constructed state. Can we move the relevant variables into that
684// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800685struct OverUseDetectorOptions {
686 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700687 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800688 initial_offset(0),
689 initial_e(),
690 initial_process_noise(),
691 initial_avg_noise(0.0),
692 initial_var_noise(50) {
693 initial_e[0][0] = 100;
694 initial_e[1][1] = 1e-1;
695 initial_e[0][1] = initial_e[1][0] = 0;
696 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800697 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800698 }
699 double initial_slope;
700 double initial_offset;
701 double initial_e[2][2];
702 double initial_process_noise[2];
703 double initial_avg_noise;
704 double initial_var_noise;
705};
706
wu@webrtc.orga9890802013-12-13 00:21:03 +0000707// This structure will have the information about when packet is actually
708// received by socket.
709struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000710 PacketTime() : timestamp(-1), not_before(-1) {}
711 PacketTime(int64_t timestamp, int64_t not_before)
solenberg634b86e2016-09-01 07:54:53 -0700712 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orga9890802013-12-13 00:21:03 +0000713
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000714 int64_t timestamp; // Receive time after socket delivers the data.
715 int64_t not_before; // Earliest possible time the data could have arrived,
716 // indicating the potential error in the |timestamp|
717 // value,in case the system is busy.
718 // For example, the time of the last select() call.
719 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000720};
721
isheriff6b4b5f32016-06-08 00:24:21 -0700722// Minimum and maximum playout delay values from capture to render.
723// These are best effort values.
724//
725// A value < 0 indicates no change from previous valid value.
726//
727// min = max = 0 indicates that the receiver should try and render
728// frame as soon as possible.
729//
730// min = x, max = y indicates that the receiver is free to adapt
731// in the range (x, y) based on network jitter.
732//
733// Note: Given that this gets embedded in a union, it is up-to the owner to
734// initialize these values.
735struct PlayoutDelay {
736 int min_ms;
737 int max_ms;
738};
739
Steve Antona3251dd2017-07-21 09:58:31 -0700740// Class to represent the value of RTP header extensions that are
741// variable-length strings (e.g., RtpStreamId and RtpMid).
danilchapef8d7732017-04-19 02:59:48 -0700742// Unlike std::string, it can be copied with memcpy and cleared with memset.
Steve Antona3251dd2017-07-21 09:58:31 -0700743//
744// Empty value represents unset header extension (use empty() to query).
745class StringRtpHeaderExtension {
danilchapef8d7732017-04-19 02:59:48 -0700746 public:
Steve Antona3251dd2017-07-21 09:58:31 -0700747 // String RTP header extensions are limited to 16 bytes because it is the
748 // maximum length that can be encoded with one-byte header extensions.
danilchapef8d7732017-04-19 02:59:48 -0700749 static constexpr size_t kMaxSize = 16;
750
eladalond0244c22017-06-08 04:19:13 -0700751 static bool IsLegalName(rtc::ArrayView<const char> name);
752
Steve Antona3251dd2017-07-21 09:58:31 -0700753 StringRtpHeaderExtension() { value_[0] = 0; }
754 explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
danilchapef8d7732017-04-19 02:59:48 -0700755 Set(value.data(), value.size());
756 }
Steve Antona3251dd2017-07-21 09:58:31 -0700757 StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
758 StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
759 default;
danilchapef8d7732017-04-19 02:59:48 -0700760
761 bool empty() const { return value_[0] == 0; }
762 const char* data() const { return value_; }
763 size_t size() const { return strnlen(value_, kMaxSize); }
764
765 void Set(rtc::ArrayView<const uint8_t> value) {
766 Set(reinterpret_cast<const char*>(value.data()), value.size());
767 }
768 void Set(const char* data, size_t size);
769
Steve Antona3251dd2017-07-21 09:58:31 -0700770 friend bool operator==(const StringRtpHeaderExtension& lhs,
771 const StringRtpHeaderExtension& rhs) {
danilchapef8d7732017-04-19 02:59:48 -0700772 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
773 }
Steve Antona3251dd2017-07-21 09:58:31 -0700774 friend bool operator!=(const StringRtpHeaderExtension& lhs,
775 const StringRtpHeaderExtension& rhs) {
danilchapef8d7732017-04-19 02:59:48 -0700776 return !(lhs == rhs);
777 }
778
779 private:
780 char value_[kMaxSize];
781};
782
Steve Antona3251dd2017-07-21 09:58:31 -0700783// StreamId represents RtpStreamId which is a string.
784typedef StringRtpHeaderExtension StreamId;
785
786// Mid represents RtpMid which is a string.
787typedef StringRtpHeaderExtension Mid;
788
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000789struct RTPHeaderExtension {
sprang@webrtc.org30933902015-03-17 14:33:12 +0000790 RTPHeaderExtension();
eladalon98b1b7d2017-09-11 08:48:26 -0700791 RTPHeaderExtension(const RTPHeaderExtension& other);
792 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000793
794 bool hasTransmissionTimeOffset;
795 int32_t transmissionTimeOffset;
796 bool hasAbsoluteSendTime;
797 uint32_t absoluteSendTime;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000798 bool hasTransportSequenceNumber;
799 uint16_t transportSequenceNumber;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000800
801 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
802 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
803 bool hasAudioLevel;
Minyue4cee4192015-08-10 15:08:36 +0200804 bool voiceActivity;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000805 uint8_t audioLevel;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000806
807 // For Coordination of Video Orientation. See
808 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
809 // ts_126114v120700p.pdf
810 bool hasVideoRotation;
magjed71eb61c2016-09-08 03:24:58 -0700811 VideoRotation videoRotation;
isheriff6b4b5f32016-06-08 00:24:21 -0700812
ilnik00d802b2017-04-11 10:34:31 -0700813 // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
814 // a corresponding bool flag.
815 bool hasVideoContentType;
816 VideoContentType videoContentType;
817
ilnik04f4d122017-06-19 07:18:55 -0700818 bool has_video_timing;
ilnik2edc6842017-07-06 03:06:50 -0700819 VideoSendTiming video_timing;
ilnik04f4d122017-06-19 07:18:55 -0700820
isheriff6b4b5f32016-06-08 00:24:21 -0700821 PlayoutDelay playout_delay = {-1, -1};
danilchapef8d7732017-04-19 02:59:48 -0700822
823 // For identification of a stream when ssrc is not signaled. See
824 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
825 // TODO(danilchap): Update url from draft to release version.
826 StreamId stream_id;
827 StreamId repaired_stream_id;
Steve Antona3251dd2017-07-21 09:58:31 -0700828
829 // For identifying the media section used to interpret this RTP packet. See
830 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
831 Mid mid;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000832};
833
834struct RTPHeader {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000835 RTPHeader();
eladalon98b1b7d2017-09-11 08:48:26 -0700836 RTPHeader(const RTPHeader& other);
837 RTPHeader& operator=(const RTPHeader& other);
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000838
839 bool markerBit;
840 uint8_t payloadType;
841 uint16_t sequenceNumber;
842 uint32_t timestamp;
843 uint32_t ssrc;
844 uint8_t numCSRCs;
845 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000846 size_t paddingLength;
847 size_t headerLength;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000848 int payload_type_frequency;
849 RTPHeaderExtension extension;
850};
851
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000852struct RtpPacketCounter {
853 RtpPacketCounter()
solenberg634b86e2016-09-01 07:54:53 -0700854 : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000855
856 void Add(const RtpPacketCounter& other) {
857 header_bytes += other.header_bytes;
858 payload_bytes += other.payload_bytes;
859 padding_bytes += other.padding_bytes;
860 packets += other.packets;
861 }
862
Erik Språng22c2b482016-03-01 09:40:42 +0100863 void Subtract(const RtpPacketCounter& other) {
kwibergb890c95c2016-11-29 05:30:40 -0800864 RTC_DCHECK_GE(header_bytes, other.header_bytes);
Erik Språng22c2b482016-03-01 09:40:42 +0100865 header_bytes -= other.header_bytes;
kwibergb890c95c2016-11-29 05:30:40 -0800866 RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
Erik Språng22c2b482016-03-01 09:40:42 +0100867 payload_bytes -= other.payload_bytes;
kwibergb890c95c2016-11-29 05:30:40 -0800868 RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
Erik Språng22c2b482016-03-01 09:40:42 +0100869 padding_bytes -= other.padding_bytes;
kwibergb890c95c2016-11-29 05:30:40 -0800870 RTC_DCHECK_GE(packets, other.packets);
Erik Språng22c2b482016-03-01 09:40:42 +0100871 packets -= other.packets;
872 }
873
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000874 void AddPacket(size_t packet_length, const RTPHeader& header) {
875 ++packets;
876 header_bytes += header.headerLength;
877 padding_bytes += header.paddingLength;
878 payload_bytes +=
879 packet_length - (header.headerLength + header.paddingLength);
880 }
881
882 size_t TotalBytes() const {
883 return header_bytes + payload_bytes + padding_bytes;
884 }
885
886 size_t header_bytes; // Number of bytes used by RTP headers.
887 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
888 size_t padding_bytes; // Number of padding bytes.
889 uint32_t packets; // Number of packets.
890};
891
892// Data usage statistics for a (rtp) stream.
893struct StreamDataCounters {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000894 StreamDataCounters();
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000895
896 void Add(const StreamDataCounters& other) {
897 transmitted.Add(other.transmitted);
898 retransmitted.Add(other.retransmitted);
899 fec.Add(other.fec);
900 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -0700901 (other.first_packet_time_ms < first_packet_time_ms ||
902 first_packet_time_ms == -1)) {
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000903 // Use oldest time.
904 first_packet_time_ms = other.first_packet_time_ms;
905 }
906 }
907
Erik Språng22c2b482016-03-01 09:40:42 +0100908 void Subtract(const StreamDataCounters& other) {
909 transmitted.Subtract(other.transmitted);
910 retransmitted.Subtract(other.retransmitted);
911 fec.Subtract(other.fec);
912 if (other.first_packet_time_ms != -1 &&
913 (other.first_packet_time_ms > first_packet_time_ms ||
914 first_packet_time_ms == -1)) {
915 // Use youngest time.
916 first_packet_time_ms = other.first_packet_time_ms;
917 }
918 }
919
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000920 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
921 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
922 }
923
924 // Returns the number of bytes corresponding to the actual media payload (i.e.
925 // RTP headers, padding, retransmissions and fec packets are excluded).
926 // Note this function does not have meaning for an RTX stream.
927 size_t MediaPayloadBytes() const {
928 return transmitted.payload_bytes - retransmitted.payload_bytes -
929 fec.payload_bytes;
930 }
931
solenberg634b86e2016-09-01 07:54:53 -0700932 int64_t first_packet_time_ms; // Time when first packet is sent/received.
933 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000934 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
solenberg634b86e2016-09-01 07:54:53 -0700935 RtpPacketCounter fec; // Number of redundancy packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000936};
937
938// Callback, called whenever byte/packet counts have been updated.
939class StreamDataCountersCallback {
940 public:
941 virtual ~StreamDataCountersCallback() {}
942
943 virtual void DataCountersUpdated(const StreamDataCounters& counters,
944 uint32_t ssrc) = 0;
945};
pbosda903ea2015-10-02 02:36:56 -0700946
947// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
948// RTCP mode is described by RFC 5506.
949enum class RtcpMode { kOff, kCompound, kReducedSize };
950
pbos1ba8d392016-05-01 20:18:34 -0700951enum NetworkState {
952 kNetworkUp,
953 kNetworkDown,
954};
955
sprangdb2a9fc2017-08-09 06:42:32 -0700956struct RtpKeepAliveConfig final {
sprang168794c2017-07-06 04:38:06 -0700957 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
958 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
959 // payload type of 20 as long as the other end has not negotiated the use of
960 // this value. If this value has already been negotiated, then some other
961 // unused static payload type from table 5 of RFC 3551 shall be used and set
962 // in |payload_type|.
963 int64_t timeout_interval_ms = -1;
964 uint8_t payload_type = 20;
sprangdb2a9fc2017-08-09 06:42:32 -0700965
966 bool operator==(const RtpKeepAliveConfig& o) const {
967 return timeout_interval_ms == o.timeout_interval_ms &&
968 payload_type == o.payload_type;
969 }
970 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
sprang168794c2017-07-06 04:38:06 -0700971};
972
niklase@google.com470e71d2011-07-07 08:21:25 +0000973} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000974
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200975#endif // COMMON_TYPES_H_