blob: b2fcf17a481d062aa704175694b57b66438d3301 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h> // For size_t
15#include <cstdint>
16
Niels Möller3c7d5992018-10-19 15:29:54 +020017#include "absl/strings/match.h"
Erik Språng566124a2018-04-23 12:32:22 +020018// TODO(sprang): Remove this include when all usage includes it directly.
19#include "api/video/video_bitrate_allocation.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/checks.h"
21#include "rtc_base/deprecation.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000023#if defined(_MSC_VER)
24// Disable "new behavior: elements of array will be default initialized"
25// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070026#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000027#endif
28
Peter Boström8b79b072016-02-26 16:31:37 +010029#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000030
niklase@google.com470e71d2011-07-07 08:21:25 +000031namespace webrtc {
32
pbos22993e12015-10-19 02:39:06 -070033enum FrameType {
34 kEmptyFrame = 0,
35 kAudioFrameSpeech = 1,
36 kAudioFrameCN = 2,
37 kVideoFrameKey = 3,
38 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000039};
40
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000041// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000042struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000043 RtcpStatistics()
solenberg634b86e2016-09-01 07:54:53 -070044 : fraction_lost(0),
srte186d9c32017-08-04 05:03:53 -070045 packets_lost(0),
46 extended_highest_sequence_number(0),
solenberg634b86e2016-09-01 07:54:53 -070047 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000048
49 uint8_t fraction_lost;
Danil Chapovalov3daabad2018-08-15 17:12:12 +020050 int32_t packets_lost; // Defined as a 24 bit signed integer in RTCP
51 uint32_t extended_highest_sequence_number;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000052 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000053};
54
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000055class RtcpStatisticsCallback {
56 public:
57 virtual ~RtcpStatisticsCallback() {}
58
59 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
60 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000061 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000062};
63
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000064// Statistics for RTCP packet types.
65struct RtcpPacketTypeCounter {
66 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070067 : first_packet_time_ms(-1),
68 nack_packets(0),
69 fir_packets(0),
70 pli_packets(0),
71 nack_requests(0),
72 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000073
74 void Add(const RtcpPacketTypeCounter& other) {
75 nack_packets += other.nack_packets;
76 fir_packets += other.fir_packets;
77 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000078 nack_requests += other.nack_requests;
79 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000080 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -070081 (other.first_packet_time_ms < first_packet_time_ms ||
82 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000083 // Use oldest time.
84 first_packet_time_ms = other.first_packet_time_ms;
85 }
86 }
87
sprang07fb9be2016-02-24 07:55:00 -080088 void Subtract(const RtcpPacketTypeCounter& other) {
89 nack_packets -= other.nack_packets;
90 fir_packets -= other.fir_packets;
91 pli_packets -= other.pli_packets;
92 nack_requests -= other.nack_requests;
93 unique_nack_requests -= other.unique_nack_requests;
94 if (other.first_packet_time_ms != -1 &&
95 (other.first_packet_time_ms > first_packet_time_ms ||
96 first_packet_time_ms == -1)) {
97 // Use youngest time.
98 first_packet_time_ms = other.first_packet_time_ms;
99 }
100 }
101
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000102 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
103 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000104 }
105
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000106 int UniqueNackRequestsInPercent() const {
107 if (nack_requests == 0) {
108 return 0;
109 }
solenberg634b86e2016-09-01 07:54:53 -0700110 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
111 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000112 }
113
solenberg634b86e2016-09-01 07:54:53 -0700114 int64_t first_packet_time_ms; // Time when first packet is sent/received.
115 uint32_t nack_packets; // Number of RTCP NACK packets.
116 uint32_t fir_packets; // Number of RTCP FIR packets.
117 uint32_t pli_packets; // Number of RTCP PLI packets.
118 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000119 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000120};
121
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000122class RtcpPacketTypeCounterObserver {
123 public:
124 virtual ~RtcpPacketTypeCounterObserver() {}
125 virtual void RtcpPacketTypesCounterUpdated(
126 uint32_t ssrc,
127 const RtcpPacketTypeCounter& packet_counter) = 0;
128};
129
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000130// Callback, used to notify an observer whenever new rates have been estimated.
131class BitrateStatisticsObserver {
132 public:
133 virtual ~BitrateStatisticsObserver() {}
134
sprangcd349d92016-07-13 09:11:28 -0700135 virtual void Notify(uint32_t total_bitrate_bps,
136 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000137 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000138};
139
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000140struct FrameCounts {
141 FrameCounts() : key_frames(0), delta_frames(0) {}
142 int key_frames;
143 int delta_frames;
144};
145
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000146// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000147class FrameCountObserver {
148 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000149 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000150 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
151 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000152};
153
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000154// Callback, used to notify an observer whenever the send-side delay is updated.
155class SendSideDelayObserver {
156 public:
157 virtual ~SendSideDelayObserver() {}
158 virtual void SendSideDelayUpdated(int avg_delay_ms,
159 int max_delay_ms,
160 uint32_t ssrc) = 0;
161};
162
asapersson35151f32016-05-02 23:44:01 -0700163// Callback, used to notify an observer whenever a packet is sent to the
164// transport.
165// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
166// Remove SendSideDelayObserver once possible.
167class SendPacketObserver {
168 public:
169 virtual ~SendPacketObserver() {}
170 virtual void OnSendPacket(uint16_t packet_id,
171 int64_t capture_time_ms,
172 uint32_t ssrc) = 0;
173};
174
michaelt4da30442016-11-17 01:38:43 -0800175// Callback, used to notify an observer when the overhead per packet
176// has changed.
177class OverheadObserver {
178 public:
179 virtual ~OverheadObserver() = default;
180 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
181};
182
niklase@google.com470e71d2011-07-07 08:21:25 +0000183// ==================================================================
184// Voice specific types
185// ==================================================================
186
187// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000188struct CodecInst {
189 int pltype;
190 char plname[RTP_PAYLOAD_NAME_SIZE];
191 int plfreq;
192 int pacsize;
Peter Kasting69558702016-01-12 16:26:35 -0800193 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000194 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
195
196 bool operator==(const CodecInst& other) const {
197 return pltype == other.pltype &&
Niels Möller2edab4c2018-10-22 09:48:08 +0200198 absl::EqualsIgnoreCase(plname, other.plname) &&
solenberg634b86e2016-09-01 07:54:53 -0700199 plfreq == other.plfreq && pacsize == other.pacsize &&
200 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000201 }
202
solenberg634b86e2016-09-01 07:54:53 -0700203 bool operator!=(const CodecInst& other) const { return !(*this == other); }
niklase@google.com470e71d2011-07-07 08:21:25 +0000204};
205
niklase@google.com470e71d2011-07-07 08:21:25 +0000206// RTP
solenberg634b86e2016-09-01 07:54:53 -0700207enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
solenberg634b86e2016-09-01 07:54:53 -0700209// NETEQ statistics.
210struct NetworkStatistics {
211 // current jitter buffer size in ms
212 uint16_t currentBufferSize;
213 // preferred (optimal) buffer size in ms
214 uint16_t preferredBufferSize;
215 // adding extra delay due to "peaky jitter"
216 bool jitterPeaksFound;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200217 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
218 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton2dbc69f2017-08-24 17:15:13 -0700219 uint64_t totalSamplesReceived;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700220 uint64_t concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200221 uint64_t concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200222 uint64_t jitterBufferDelayMs;
223 // Stats below DO NOT correspond directly to anything in the WebRTC stats
solenberg634b86e2016-09-01 07:54:53 -0700224 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
225 uint16_t currentPacketLossRate;
226 // Late loss rate; fraction between 0 and 1, scaled to Q14.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200227 union {
228 RTC_DEPRECATED uint16_t currentDiscardRate;
229 };
solenberg634b86e2016-09-01 07:54:53 -0700230 // fraction (of original stream) of synthesized audio inserted through
231 // expansion (in Q14)
232 uint16_t currentExpandRate;
233 // fraction (of original stream) of synthesized speech inserted through
234 // expansion (in Q14)
235 uint16_t currentSpeechExpandRate;
236 // fraction of synthesized speech inserted through pre-emptive expansion
237 // (in Q14)
238 uint16_t currentPreemptiveRate;
239 // fraction of data removed through acceleration (in Q14)
240 uint16_t currentAccelerateRate;
241 // fraction of data coming from secondary decoding (in Q14)
242 uint16_t currentSecondaryDecodedRate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200243 // Fraction of secondary data, including FEC and RED, that is discarded (in
244 // Q14). Discarding of secondary data can be caused by the reception of the
245 // primary data, obsoleting the secondary data. It can also be caused by early
246 // or late arrival of secondary data.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200247 uint16_t currentSecondaryDiscardedRate;
solenberg634b86e2016-09-01 07:54:53 -0700248 // clock-drift in parts-per-million (negative or positive)
249 int32_t clockDriftPPM;
250 // average packet waiting time in the jitter buffer (ms)
251 int meanWaitingTimeMs;
252 // median packet waiting time in the jitter buffer (ms)
253 int medianWaitingTimeMs;
254 // min packet waiting time in the jitter buffer (ms)
255 int minWaitingTimeMs;
256 // max packet waiting time in the jitter buffer (ms)
257 int maxWaitingTimeMs;
258 // added samples in off mode due to packet loss
259 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260};
261
wu@webrtc.org24301a62013-12-13 19:17:43 +0000262// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
263struct AudioDecodingCallStats {
264 AudioDecodingCallStats()
265 : calls_to_silence_generator(0),
266 calls_to_neteq(0),
267 decoded_normal(0),
268 decoded_plc(0),
269 decoded_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700270 decoded_plc_cng(0),
271 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43 +0000272
273 int calls_to_silence_generator; // Number of calls where silence generated,
274 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 07:54:53 -0700275 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000276 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 07:54:53 -0700277 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000278 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
Yves Gerey665174f2018-06-19 15:03:05 +0200279 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 01:47:12 -0700280 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000281};
282
niklase@google.com470e71d2011-07-07 08:21:25 +0000283// ==================================================================
284// Video specific types
285// ==================================================================
286
nisseeb44b392017-04-28 07:18:05 -0700287// TODO(nisse): Delete, and switch to fourcc values everywhere?
288// Supported video types.
289enum class VideoType {
290 kUnknown,
291 kI420,
292 kIYUV,
293 kRGB24,
294 kABGR,
295 kARGB,
296 kARGB4444,
297 kRGB565,
298 kARGB1555,
299 kYUY2,
300 kYV12,
301 kUYVY,
302 kMJPEG,
303 kNV21,
304 kNV12,
305 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25 +0000306};
307
magjede69a1a92016-11-25 10:06:31 -0800308// TODO(magjed): Move this and other H264 related classes out to their own file.
309namespace H264 {
310
311enum Profile {
312 kProfileConstrainedBaseline,
313 kProfileBaseline,
314 kProfileMain,
315 kProfileConstrainedHigh,
316 kProfileHigh,
317};
318
319} // namespace H264
320
niklase@google.com470e71d2011-07-07 08:21:25 +0000321// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000322enum VideoCodecType {
Niels Möller520ca4e2018-06-04 11:14:38 +0200323 // There are various memset(..., 0, ...) calls in the code that rely on
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +0200324 // kVideoCodecGeneric being zero.
325 kVideoCodecGeneric = 0,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000326 kVideoCodecVP8,
327 kVideoCodecVP9,
328 kVideoCodecH264,
329 kVideoCodecI420,
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800330 kVideoCodecMultiplex,
niklase@google.com470e71d2011-07-07 08:21:25 +0000331};
332
Sergey Silkin13e74342018-03-02 12:28:00 +0100333struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100334 bool operator==(const SpatialLayer& other) const;
335 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
336
solenberg634b86e2016-09-01 07:54:53 -0700337 unsigned short width;
338 unsigned short height;
Sergey Silkin1946a3f2018-08-22 11:42:16 +0200339 float maxFramerate; // fps.
solenberg634b86e2016-09-01 07:54:53 -0700340 unsigned char numberOfTemporalLayers;
341 unsigned int maxBitrate; // kilobits/sec.
342 unsigned int targetBitrate; // kilobits/sec.
343 unsigned int minBitrate; // kilobits/sec.
344 unsigned int qpMax; // minimum quality
Seth Hampsonf6464c92018-01-17 13:55:14 -0800345 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000346};
347
Sergey Silkin13e74342018-03-02 12:28:00 +0100348// Simulcast is when the same stream is encoded multiple times with different
349// settings such as resolution.
350typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800351
stefan64c0a0a2015-11-27 01:02:31 -0800352// Bandwidth over-use detector options. These are used to drive
353// experimentation with bandwidth estimation parameters.
354// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800355// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
356// default constructed state. Can we move the relevant variables into that
357// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800358struct OverUseDetectorOptions {
359 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700360 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800361 initial_offset(0),
362 initial_e(),
363 initial_process_noise(),
364 initial_avg_noise(0.0),
365 initial_var_noise(50) {
366 initial_e[0][0] = 100;
367 initial_e[1][1] = 1e-1;
368 initial_e[0][1] = initial_e[1][0] = 0;
369 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800370 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800371 }
372 double initial_slope;
373 double initial_offset;
374 double initial_e[2][2];
375 double initial_process_noise[2];
376 double initial_avg_noise;
377 double initial_var_noise;
378};
379
isheriff6b4b5f32016-06-08 00:24:21 -0700380// Minimum and maximum playout delay values from capture to render.
381// These are best effort values.
382//
383// A value < 0 indicates no change from previous valid value.
384//
385// min = max = 0 indicates that the receiver should try and render
386// frame as soon as possible.
387//
388// min = x, max = y indicates that the receiver is free to adapt
389// in the range (x, y) based on network jitter.
390//
391// Note: Given that this gets embedded in a union, it is up-to the owner to
392// initialize these values.
393struct PlayoutDelay {
394 int min_ms;
395 int max_ms;
396};
397
niklase@google.com470e71d2011-07-07 08:21:25 +0000398} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000399
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200400#endif // COMMON_TYPES_H_