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 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 17 | // TODO(sprang): Remove this include when all usage includes it directly. |
| 18 | #include "api/video/video_bitrate_allocation.h" |
Niels Möller | 22b70ff | 2018-11-20 11:06:58 +0100 | [diff] [blame] | 19 | // TODO(bugs.webrtc.org/7660): Delete include once downstream code is updated. |
| 20 | #include "api/video/video_codec_type.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 +0000 | [diff] [blame] | 22 | #if defined(_MSC_VER) |
| 23 | // Disable "new behavior: elements of array will be default initialized" |
| 24 | // warning. Affects OverUseDetectorOptions. |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 25 | #pragma warning(disable : 4351) |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 +0000 | [diff] [blame] | 26 | #endif |
| 27 | |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 28 | #define RTP_PAYLOAD_NAME_SIZE 32u |
henrika@webrtc.org | f75901f | 2012-01-16 08:45:42 +0000 | [diff] [blame] | 29 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | namespace webrtc { |
| 31 | |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 32 | enum FrameType { |
| 33 | kEmptyFrame = 0, |
| 34 | kAudioFrameSpeech = 1, |
| 35 | kAudioFrameCN = 2, |
| 36 | kVideoFrameKey = 3, |
| 37 | kVideoFrameDelta = 4, |
sprang@webrtc.org | 71f055f | 2013-12-04 15:09:27 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 40 | // Statistics for RTCP packet types. |
| 41 | struct RtcpPacketTypeCounter { |
| 42 | RtcpPacketTypeCounter() |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 43 | : first_packet_time_ms(-1), |
| 44 | nack_packets(0), |
| 45 | fir_packets(0), |
| 46 | pli_packets(0), |
| 47 | nack_requests(0), |
| 48 | unique_nack_requests(0) {} |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 49 | |
| 50 | void Add(const RtcpPacketTypeCounter& other) { |
| 51 | nack_packets += other.nack_packets; |
| 52 | fir_packets += other.fir_packets; |
| 53 | pli_packets += other.pli_packets; |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 54 | nack_requests += other.nack_requests; |
| 55 | unique_nack_requests += other.unique_nack_requests; |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 56 | if (other.first_packet_time_ms != -1 && |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 57 | (other.first_packet_time_ms < first_packet_time_ms || |
| 58 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 59 | // Use oldest time. |
| 60 | first_packet_time_ms = other.first_packet_time_ms; |
| 61 | } |
| 62 | } |
| 63 | |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 64 | void Subtract(const RtcpPacketTypeCounter& other) { |
| 65 | nack_packets -= other.nack_packets; |
| 66 | fir_packets -= other.fir_packets; |
| 67 | pli_packets -= other.pli_packets; |
| 68 | nack_requests -= other.nack_requests; |
| 69 | unique_nack_requests -= other.unique_nack_requests; |
| 70 | if (other.first_packet_time_ms != -1 && |
| 71 | (other.first_packet_time_ms > first_packet_time_ms || |
| 72 | first_packet_time_ms == -1)) { |
| 73 | // Use youngest time. |
| 74 | first_packet_time_ms = other.first_packet_time_ms; |
| 75 | } |
| 76 | } |
| 77 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 78 | int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { |
| 79 | 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] | 80 | } |
| 81 | |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 82 | int UniqueNackRequestsInPercent() const { |
| 83 | if (nack_requests == 0) { |
| 84 | return 0; |
| 85 | } |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 86 | return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) + |
| 87 | 0.5f); |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 88 | } |
| 89 | |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 90 | int64_t first_packet_time_ms; // Time when first packet is sent/received. |
| 91 | uint32_t nack_packets; // Number of RTCP NACK packets. |
| 92 | uint32_t fir_packets; // Number of RTCP FIR packets. |
| 93 | uint32_t pli_packets; // Number of RTCP PLI packets. |
| 94 | uint32_t nack_requests; // Number of NACKed RTP packets. |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 95 | uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 98 | class RtcpPacketTypeCounterObserver { |
| 99 | public: |
| 100 | virtual ~RtcpPacketTypeCounterObserver() {} |
| 101 | virtual void RtcpPacketTypesCounterUpdated( |
| 102 | uint32_t ssrc, |
| 103 | const RtcpPacketTypeCounter& packet_counter) = 0; |
| 104 | }; |
| 105 | |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 106 | // Callback, used to notify an observer whenever new rates have been estimated. |
| 107 | class BitrateStatisticsObserver { |
| 108 | public: |
| 109 | virtual ~BitrateStatisticsObserver() {} |
| 110 | |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 111 | virtual void Notify(uint32_t total_bitrate_bps, |
| 112 | uint32_t retransmit_bitrate_bps, |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 113 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 116 | struct FrameCounts { |
| 117 | FrameCounts() : key_frames(0), delta_frames(0) {} |
| 118 | int key_frames; |
| 119 | int delta_frames; |
| 120 | }; |
| 121 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 122 | // 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] | 123 | class FrameCountObserver { |
| 124 | public: |
sprang@webrtc.org | 72964bd | 2013-11-21 09:09:54 +0000 | [diff] [blame] | 125 | virtual ~FrameCountObserver() {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 126 | virtual void FrameCountUpdated(const FrameCounts& frame_counts, |
| 127 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 130 | // Callback, used to notify an observer whenever the send-side delay is updated. |
| 131 | class SendSideDelayObserver { |
| 132 | public: |
| 133 | virtual ~SendSideDelayObserver() {} |
| 134 | virtual void SendSideDelayUpdated(int avg_delay_ms, |
| 135 | int max_delay_ms, |
| 136 | uint32_t ssrc) = 0; |
| 137 | }; |
| 138 | |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 139 | // Callback, used to notify an observer whenever a packet is sent to the |
| 140 | // transport. |
| 141 | // TODO(asapersson): This class will remove the need for SendSideDelayObserver. |
| 142 | // Remove SendSideDelayObserver once possible. |
| 143 | class SendPacketObserver { |
| 144 | public: |
| 145 | virtual ~SendPacketObserver() {} |
| 146 | virtual void OnSendPacket(uint16_t packet_id, |
| 147 | int64_t capture_time_ms, |
| 148 | uint32_t ssrc) = 0; |
| 149 | }; |
| 150 | |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 151 | // Callback, used to notify an observer when the overhead per packet |
| 152 | // has changed. |
| 153 | class OverheadObserver { |
| 154 | public: |
| 155 | virtual ~OverheadObserver() = default; |
| 156 | virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0; |
| 157 | }; |
| 158 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | // RTP |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 160 | enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | // ================================================================== |
| 163 | // Video specific types |
| 164 | // ================================================================== |
| 165 | |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 166 | // TODO(nisse): Delete, and switch to fourcc values everywhere? |
| 167 | // Supported video types. |
| 168 | enum class VideoType { |
| 169 | kUnknown, |
| 170 | kI420, |
| 171 | kIYUV, |
| 172 | kRGB24, |
| 173 | kABGR, |
| 174 | kARGB, |
| 175 | kARGB4444, |
| 176 | kRGB565, |
| 177 | kARGB1555, |
| 178 | kYUY2, |
| 179 | kYV12, |
| 180 | kUYVY, |
| 181 | kMJPEG, |
| 182 | kNV21, |
| 183 | kNV12, |
| 184 | kBGRA, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 187 | // TODO(magjed): Move this and other H264 related classes out to their own file. |
| 188 | namespace H264 { |
| 189 | |
| 190 | enum Profile { |
| 191 | kProfileConstrainedBaseline, |
| 192 | kProfileBaseline, |
| 193 | kProfileMain, |
| 194 | kProfileConstrainedHigh, |
| 195 | kProfileHigh, |
| 196 | }; |
| 197 | |
| 198 | } // namespace H264 |
| 199 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 200 | struct SpatialLayer { |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 201 | bool operator==(const SpatialLayer& other) const; |
| 202 | bool operator!=(const SpatialLayer& other) const { return !(*this == other); } |
| 203 | |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 204 | unsigned short width; |
| 205 | unsigned short height; |
Sergey Silkin | 1946a3f | 2018-08-22 11:42:16 +0200 | [diff] [blame] | 206 | float maxFramerate; // fps. |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 207 | unsigned char numberOfTemporalLayers; |
| 208 | unsigned int maxBitrate; // kilobits/sec. |
| 209 | unsigned int targetBitrate; // kilobits/sec. |
| 210 | unsigned int minBitrate; // kilobits/sec. |
| 211 | unsigned int qpMax; // minimum quality |
Seth Hampson | f6464c9 | 2018-01-17 13:55:14 -0800 | [diff] [blame] | 212 | bool active; // encoded and sent. |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 215 | // Simulcast is when the same stream is encoded multiple times with different |
| 216 | // settings such as resolution. |
| 217 | typedef SpatialLayer SimulcastStream; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 218 | |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 219 | // Bandwidth over-use detector options. These are used to drive |
| 220 | // experimentation with bandwidth estimation parameters. |
| 221 | // See modules/remote_bitrate_estimator/overuse_detector.h |
terelius | 84f83f8 | 2016-12-27 10:43:01 -0800 | [diff] [blame] | 222 | // TODO(terelius): This is only used in overuse_estimator.cc, and only in the |
| 223 | // default constructed state. Can we move the relevant variables into that |
| 224 | // class and delete this? See also disabled warning at line 27 |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 225 | struct OverUseDetectorOptions { |
| 226 | OverUseDetectorOptions() |
solenberg | 634b86e | 2016-09-01 07:54:53 -0700 | [diff] [blame] | 227 | : initial_slope(8.0 / 512.0), |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 228 | initial_offset(0), |
| 229 | initial_e(), |
| 230 | initial_process_noise(), |
| 231 | initial_avg_noise(0.0), |
| 232 | initial_var_noise(50) { |
| 233 | initial_e[0][0] = 100; |
| 234 | initial_e[1][1] = 1e-1; |
| 235 | initial_e[0][1] = initial_e[1][0] = 0; |
| 236 | initial_process_noise[0] = 1e-13; |
stefan | 1069cac | 2016-03-10 05:13:21 -0800 | [diff] [blame] | 237 | initial_process_noise[1] = 1e-3; |
stefan | 64c0a0a | 2015-11-27 01:02:31 -0800 | [diff] [blame] | 238 | } |
| 239 | double initial_slope; |
| 240 | double initial_offset; |
| 241 | double initial_e[2][2]; |
| 242 | double initial_process_noise[2]; |
| 243 | double initial_avg_noise; |
| 244 | double initial_var_noise; |
| 245 | }; |
| 246 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 247 | // Minimum and maximum playout delay values from capture to render. |
| 248 | // These are best effort values. |
| 249 | // |
| 250 | // A value < 0 indicates no change from previous valid value. |
| 251 | // |
| 252 | // min = max = 0 indicates that the receiver should try and render |
| 253 | // frame as soon as possible. |
| 254 | // |
| 255 | // min = x, max = y indicates that the receiver is free to adapt |
| 256 | // in the range (x, y) based on network jitter. |
| 257 | // |
| 258 | // Note: Given that this gets embedded in a union, it is up-to the owner to |
| 259 | // initialize these values. |
| 260 | struct PlayoutDelay { |
| 261 | int min_ms; |
| 262 | int max_ms; |
| 263 | }; |
| 264 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 265 | } // namespace webrtc |
andrew@webrtc.org | eda189b | 2013-09-09 17:50:10 +0000 | [diff] [blame] | 266 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 267 | #endif // COMMON_TYPES_H_ |