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