niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
phoglund@webrtc.org | 8bfee84 | 2012-02-17 09:32:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef COMMON_TYPES_H_ |
| 12 | #define COMMON_TYPES_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> // For size_t |
| 15 | #include <cstdint> |
| 16 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 19 | // Statistics for RTCP packet types. |
| 20 | struct RtcpPacketTypeCounter { |
| 21 | RtcpPacketTypeCounter() |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 22 | : 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.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 28 | |
| 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.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 33 | nack_requests += other.nack_requests; |
| 34 | unique_nack_requests += other.unique_nack_requests; |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 35 | if (other.first_packet_time_ms != -1 && |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 36 | (other.first_packet_time_ms < first_packet_time_ms || |
| 37 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 38 | // Use oldest time. |
| 39 | first_packet_time_ms = other.first_packet_time_ms; |
| 40 | } |
| 41 | } |
| 42 | |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 43 | 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.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 57 | int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { |
| 58 | return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms); |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 59 | } |
| 60 | |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 61 | int UniqueNackRequestsInPercent() const { |
| 62 | if (nack_requests == 0) { |
| 63 | return 0; |
| 64 | } |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 65 | return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) + |
| 66 | 0.5f); |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 67 | } |
| 68 | |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 69 | 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.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 74 | uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 77 | class RtcpPacketTypeCounterObserver { |
| 78 | public: |
| 79 | virtual ~RtcpPacketTypeCounterObserver() {} |
| 80 | virtual void RtcpPacketTypesCounterUpdated( |
| 81 | uint32_t ssrc, |
| 82 | const RtcpPacketTypeCounter& packet_counter) = 0; |
| 83 | }; |
| 84 | |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 85 | // Callback, used to notify an observer whenever new rates have been estimated. |
| 86 | class BitrateStatisticsObserver { |
| 87 | public: |
| 88 | virtual ~BitrateStatisticsObserver() {} |
| 89 | |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 90 | virtual void Notify(uint32_t total_bitrate_bps, |
| 91 | uint32_t retransmit_bitrate_bps, |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 92 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 95 | struct FrameCounts { |
| 96 | FrameCounts() : key_frames(0), delta_frames(0) {} |
| 97 | int key_frames; |
| 98 | int delta_frames; |
| 99 | }; |
| 100 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 101 | // Callback, used to notify an observer whenever frame counts have been updated. |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 102 | class FrameCountObserver { |
| 103 | public: |
sprang@webrtc.org | 72964bd | 2013-11-21 09:09:54 +0000 | [diff] [blame] | 104 | virtual ~FrameCountObserver() {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 105 | virtual void FrameCountUpdated(const FrameCounts& frame_counts, |
| 106 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 109 | // Callback, used to notify an observer whenever the send-side delay is updated. |
| 110 | class 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 | |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 118 | // 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. |
| 122 | class 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 | |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 130 | // Callback, used to notify an observer when the overhead per packet |
| 131 | // has changed. |
| 132 | class OverheadObserver { |
| 133 | public: |
| 134 | virtual ~OverheadObserver() = default; |
| 135 | virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0; |
| 136 | }; |
| 137 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | // RTP |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 139 | enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | // ================================================================== |
| 142 | // Video specific types |
| 143 | // ================================================================== |
| 144 | |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 145 | // TODO(magjed): Move this and other H264 related classes out to their own file. |
| 146 | namespace H264 { |
| 147 | |
| 148 | enum Profile { |
| 149 | kProfileConstrainedBaseline, |
| 150 | kProfileBaseline, |
| 151 | kProfileMain, |
| 152 | kProfileConstrainedHigh, |
| 153 | kProfileHigh, |
| 154 | }; |
| 155 | |
| 156 | } // namespace H264 |
| 157 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 158 | struct SpatialLayer { |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 159 | bool operator==(const SpatialLayer& other) const; |
| 160 | bool operator!=(const SpatialLayer& other) const { return !(*this == other); } |
| 161 | |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 162 | unsigned short width; |
| 163 | unsigned short height; |
Sergey Silkin | 1946a3f | 2018-08-22 11:42:16 +0200 | [diff] [blame] | 164 | float maxFramerate; // fps. |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 165 | 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 Hampson | f6464c9 | 2018-01-17 13:55:14 -0800 | [diff] [blame] | 170 | bool active; // encoded and sent. |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 173 | // Simulcast is when the same stream is encoded multiple times with different |
| 174 | // settings such as resolution. |
| 175 | typedef SpatialLayer SimulcastStream; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 176 | |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 177 | // 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 |
terelius | 84f83f8 | 2016-12-27 10:43:01 -0800 | [diff] [blame] | 180 | // 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 |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 183 | struct OverUseDetectorOptions { |
| 184 | OverUseDetectorOptions() |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 185 | : initial_slope(8.0 / 512.0), |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 186 | 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; |
stefan | 1069cac | 2016-03-10 05:13:21 -0800 | [diff] [blame] | 195 | initial_process_noise[1] = 1e-3; |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 196 | } |
| 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 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 205 | // 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. |
| 218 | struct PlayoutDelay { |
| 219 | int min_ms; |
| 220 | int max_ms; |
| 221 | }; |
| 222 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | } // namespace webrtc |
andrew@webrtc.org | eda189b | 2013-09-09 17:50:10 +0000 | [diff] [blame] | 224 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 225 | #endif // COMMON_TYPES_H_ |