blob: fb677d67bb46ebfd77c8647a1e483da3889ac6dc [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
niklase@google.com470e71d2011-07-07 08:21:25 +000017namespace webrtc {
18
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000019// Statistics for RTCP packet types.
20struct RtcpPacketTypeCounter {
21 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070022 : first_packet_time_ms(-1),
23 nack_packets(0),
24 fir_packets(0),
25 pli_packets(0),
26 nack_requests(0),
27 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000028
29 void Add(const RtcpPacketTypeCounter& other) {
30 nack_packets += other.nack_packets;
31 fir_packets += other.fir_packets;
32 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000033 nack_requests += other.nack_requests;
34 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000035 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -070036 (other.first_packet_time_ms < first_packet_time_ms ||
37 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000038 // Use oldest time.
39 first_packet_time_ms = other.first_packet_time_ms;
40 }
41 }
42
sprang07fb9be2016-02-24 07:55:00 -080043 void Subtract(const RtcpPacketTypeCounter& other) {
44 nack_packets -= other.nack_packets;
45 fir_packets -= other.fir_packets;
46 pli_packets -= other.pli_packets;
47 nack_requests -= other.nack_requests;
48 unique_nack_requests -= other.unique_nack_requests;
49 if (other.first_packet_time_ms != -1 &&
50 (other.first_packet_time_ms > first_packet_time_ms ||
51 first_packet_time_ms == -1)) {
52 // Use youngest time.
53 first_packet_time_ms = other.first_packet_time_ms;
54 }
55 }
56
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000057 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
58 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000059 }
60
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000061 int UniqueNackRequestsInPercent() const {
62 if (nack_requests == 0) {
63 return 0;
64 }
solenberg634b86e2016-09-01 07:54:53 -070065 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
66 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000067 }
68
solenberg634b86e2016-09-01 07:54:53 -070069 int64_t first_packet_time_ms; // Time when first packet is sent/received.
70 uint32_t nack_packets; // Number of RTCP NACK packets.
71 uint32_t fir_packets; // Number of RTCP FIR packets.
72 uint32_t pli_packets; // Number of RTCP PLI packets.
73 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000074 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000075};
76
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000077class RtcpPacketTypeCounterObserver {
78 public:
79 virtual ~RtcpPacketTypeCounterObserver() {}
80 virtual void RtcpPacketTypesCounterUpdated(
81 uint32_t ssrc,
82 const RtcpPacketTypeCounter& packet_counter) = 0;
83};
84
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000085// Callback, used to notify an observer whenever new rates have been estimated.
86class BitrateStatisticsObserver {
87 public:
88 virtual ~BitrateStatisticsObserver() {}
89
sprangcd349d92016-07-13 09:11:28 -070090 virtual void Notify(uint32_t total_bitrate_bps,
91 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000092 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000093};
94
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000095struct FrameCounts {
96 FrameCounts() : key_frames(0), delta_frames(0) {}
97 int key_frames;
98 int delta_frames;
99};
100
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000101// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000102class FrameCountObserver {
103 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000104 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000105 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
106 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000107};
108
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000109// Callback, used to notify an observer whenever the send-side delay is updated.
110class SendSideDelayObserver {
111 public:
112 virtual ~SendSideDelayObserver() {}
113 virtual void SendSideDelayUpdated(int avg_delay_ms,
114 int max_delay_ms,
115 uint32_t ssrc) = 0;
116};
117
asapersson35151f32016-05-02 23:44:01 -0700118// Callback, used to notify an observer whenever a packet is sent to the
119// transport.
120// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
121// Remove SendSideDelayObserver once possible.
122class SendPacketObserver {
123 public:
124 virtual ~SendPacketObserver() {}
125 virtual void OnSendPacket(uint16_t packet_id,
126 int64_t capture_time_ms,
127 uint32_t ssrc) = 0;
128};
129
michaelt4da30442016-11-17 01:38:43 -0800130// Callback, used to notify an observer when the overhead per packet
131// has changed.
132class OverheadObserver {
133 public:
134 virtual ~OverheadObserver() = default;
135 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
136};
137
niklase@google.com470e71d2011-07-07 08:21:25 +0000138// RTP
solenberg634b86e2016-09-01 07:54:53 -0700139enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
niklase@google.com470e71d2011-07-07 08:21:25 +0000141// ==================================================================
142// Video specific types
143// ==================================================================
144
magjede69a1a92016-11-25 10:06:31 -0800145// TODO(magjed): Move this and other H264 related classes out to their own file.
146namespace H264 {
147
148enum Profile {
149 kProfileConstrainedBaseline,
150 kProfileBaseline,
151 kProfileMain,
152 kProfileConstrainedHigh,
153 kProfileHigh,
154};
155
156} // namespace H264
157
Sergey Silkin13e74342018-03-02 12:28:00 +0100158struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100159 bool operator==(const SpatialLayer& other) const;
160 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
161
solenberg634b86e2016-09-01 07:54:53 -0700162 unsigned short width;
163 unsigned short height;
Sergey Silkin1946a3f2018-08-22 11:42:16 +0200164 float maxFramerate; // fps.
solenberg634b86e2016-09-01 07:54:53 -0700165 unsigned char numberOfTemporalLayers;
166 unsigned int maxBitrate; // kilobits/sec.
167 unsigned int targetBitrate; // kilobits/sec.
168 unsigned int minBitrate; // kilobits/sec.
169 unsigned int qpMax; // minimum quality
Seth Hampsonf6464c92018-01-17 13:55:14 -0800170 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000171};
172
Sergey Silkin13e74342018-03-02 12:28:00 +0100173// Simulcast is when the same stream is encoded multiple times with different
174// settings such as resolution.
175typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800176
stefan64c0a0a2015-11-27 01:02:31 -0800177// Bandwidth over-use detector options. These are used to drive
178// experimentation with bandwidth estimation parameters.
179// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800180// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
181// default constructed state. Can we move the relevant variables into that
182// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800183struct OverUseDetectorOptions {
184 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700185 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800186 initial_offset(0),
187 initial_e(),
188 initial_process_noise(),
189 initial_avg_noise(0.0),
190 initial_var_noise(50) {
191 initial_e[0][0] = 100;
192 initial_e[1][1] = 1e-1;
193 initial_e[0][1] = initial_e[1][0] = 0;
194 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800195 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800196 }
197 double initial_slope;
198 double initial_offset;
199 double initial_e[2][2];
200 double initial_process_noise[2];
201 double initial_avg_noise;
202 double initial_var_noise;
203};
204
isheriff6b4b5f32016-06-08 00:24:21 -0700205// Minimum and maximum playout delay values from capture to render.
206// These are best effort values.
207//
208// A value < 0 indicates no change from previous valid value.
209//
210// min = max = 0 indicates that the receiver should try and render
211// frame as soon as possible.
212//
213// min = x, max = y indicates that the receiver is free to adapt
214// in the range (x, y) based on network jitter.
215//
216// Note: Given that this gets embedded in a union, it is up-to the owner to
217// initialize these values.
218struct PlayoutDelay {
219 int min_ms;
220 int max_ms;
221};
222
niklase@google.com470e71d2011-07-07 08:21:25 +0000223} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000224
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200225#endif // COMMON_TYPES_H_