blob: 2422ce0c31d99477a5fa40b3fce2cac3f186021c [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öller22b70ff2018-11-20 11:06:58 +010017// TODO(bugs.webrtc.org/7660): Delete include once downstream code is updated.
18#include "api/video/video_codec_type.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000020#if defined(_MSC_VER)
21// Disable "new behavior: elements of array will be default initialized"
22// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070023#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000024#endif
25
Peter Boström8b79b072016-02-26 16:31:37 +010026#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000027
niklase@google.com470e71d2011-07-07 08:21:25 +000028namespace webrtc {
29
pbos22993e12015-10-19 02:39:06 -070030enum FrameType {
31 kEmptyFrame = 0,
32 kAudioFrameSpeech = 1,
33 kAudioFrameCN = 2,
34 kVideoFrameKey = 3,
35 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000036};
37
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000038// Statistics for RTCP packet types.
39struct RtcpPacketTypeCounter {
40 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070041 : first_packet_time_ms(-1),
42 nack_packets(0),
43 fir_packets(0),
44 pli_packets(0),
45 nack_requests(0),
46 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000047
48 void Add(const RtcpPacketTypeCounter& other) {
49 nack_packets += other.nack_packets;
50 fir_packets += other.fir_packets;
51 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000052 nack_requests += other.nack_requests;
53 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000054 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -070055 (other.first_packet_time_ms < first_packet_time_ms ||
56 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000057 // Use oldest time.
58 first_packet_time_ms = other.first_packet_time_ms;
59 }
60 }
61
sprang07fb9be2016-02-24 07:55:00 -080062 void Subtract(const RtcpPacketTypeCounter& other) {
63 nack_packets -= other.nack_packets;
64 fir_packets -= other.fir_packets;
65 pli_packets -= other.pli_packets;
66 nack_requests -= other.nack_requests;
67 unique_nack_requests -= other.unique_nack_requests;
68 if (other.first_packet_time_ms != -1 &&
69 (other.first_packet_time_ms > first_packet_time_ms ||
70 first_packet_time_ms == -1)) {
71 // Use youngest time.
72 first_packet_time_ms = other.first_packet_time_ms;
73 }
74 }
75
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000076 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
77 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000078 }
79
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000080 int UniqueNackRequestsInPercent() const {
81 if (nack_requests == 0) {
82 return 0;
83 }
solenberg634b86e2016-09-01 07:54:53 -070084 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
85 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000086 }
87
solenberg634b86e2016-09-01 07:54:53 -070088 int64_t first_packet_time_ms; // Time when first packet is sent/received.
89 uint32_t nack_packets; // Number of RTCP NACK packets.
90 uint32_t fir_packets; // Number of RTCP FIR packets.
91 uint32_t pli_packets; // Number of RTCP PLI packets.
92 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000093 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000094};
95
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000096class RtcpPacketTypeCounterObserver {
97 public:
98 virtual ~RtcpPacketTypeCounterObserver() {}
99 virtual void RtcpPacketTypesCounterUpdated(
100 uint32_t ssrc,
101 const RtcpPacketTypeCounter& packet_counter) = 0;
102};
103
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000104// Callback, used to notify an observer whenever new rates have been estimated.
105class BitrateStatisticsObserver {
106 public:
107 virtual ~BitrateStatisticsObserver() {}
108
sprangcd349d92016-07-13 09:11:28 -0700109 virtual void Notify(uint32_t total_bitrate_bps,
110 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000111 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000112};
113
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000114struct FrameCounts {
115 FrameCounts() : key_frames(0), delta_frames(0) {}
116 int key_frames;
117 int delta_frames;
118};
119
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000120// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000121class FrameCountObserver {
122 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000123 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000124 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
125 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000126};
127
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000128// Callback, used to notify an observer whenever the send-side delay is updated.
129class SendSideDelayObserver {
130 public:
131 virtual ~SendSideDelayObserver() {}
132 virtual void SendSideDelayUpdated(int avg_delay_ms,
133 int max_delay_ms,
134 uint32_t ssrc) = 0;
135};
136
asapersson35151f32016-05-02 23:44:01 -0700137// Callback, used to notify an observer whenever a packet is sent to the
138// transport.
139// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
140// Remove SendSideDelayObserver once possible.
141class SendPacketObserver {
142 public:
143 virtual ~SendPacketObserver() {}
144 virtual void OnSendPacket(uint16_t packet_id,
145 int64_t capture_time_ms,
146 uint32_t ssrc) = 0;
147};
148
michaelt4da30442016-11-17 01:38:43 -0800149// Callback, used to notify an observer when the overhead per packet
150// has changed.
151class OverheadObserver {
152 public:
153 virtual ~OverheadObserver() = default;
154 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
155};
156
niklase@google.com470e71d2011-07-07 08:21:25 +0000157// RTP
solenberg634b86e2016-09-01 07:54:53 -0700158enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
niklase@google.com470e71d2011-07-07 08:21:25 +0000160// ==================================================================
161// Video specific types
162// ==================================================================
163
nisseeb44b392017-04-28 07:18:05 -0700164// TODO(nisse): Delete, and switch to fourcc values everywhere?
165// Supported video types.
166enum class VideoType {
167 kUnknown,
168 kI420,
169 kIYUV,
170 kRGB24,
171 kABGR,
172 kARGB,
173 kARGB4444,
174 kRGB565,
175 kARGB1555,
176 kYUY2,
177 kYV12,
178 kUYVY,
179 kMJPEG,
180 kNV21,
181 kNV12,
182 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25 +0000183};
184
magjede69a1a92016-11-25 10:06:31 -0800185// TODO(magjed): Move this and other H264 related classes out to their own file.
186namespace H264 {
187
188enum Profile {
189 kProfileConstrainedBaseline,
190 kProfileBaseline,
191 kProfileMain,
192 kProfileConstrainedHigh,
193 kProfileHigh,
194};
195
196} // namespace H264
197
Sergey Silkin13e74342018-03-02 12:28:00 +0100198struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100199 bool operator==(const SpatialLayer& other) const;
200 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
201
solenberg634b86e2016-09-01 07:54:53 -0700202 unsigned short width;
203 unsigned short height;
Sergey Silkin1946a3f2018-08-22 11:42:16 +0200204 float maxFramerate; // fps.
solenberg634b86e2016-09-01 07:54:53 -0700205 unsigned char numberOfTemporalLayers;
206 unsigned int maxBitrate; // kilobits/sec.
207 unsigned int targetBitrate; // kilobits/sec.
208 unsigned int minBitrate; // kilobits/sec.
209 unsigned int qpMax; // minimum quality
Seth Hampsonf6464c92018-01-17 13:55:14 -0800210 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000211};
212
Sergey Silkin13e74342018-03-02 12:28:00 +0100213// Simulcast is when the same stream is encoded multiple times with different
214// settings such as resolution.
215typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800216
stefan64c0a0a2015-11-27 01:02:31 -0800217// Bandwidth over-use detector options. These are used to drive
218// experimentation with bandwidth estimation parameters.
219// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800220// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
221// default constructed state. Can we move the relevant variables into that
222// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800223struct OverUseDetectorOptions {
224 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700225 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800226 initial_offset(0),
227 initial_e(),
228 initial_process_noise(),
229 initial_avg_noise(0.0),
230 initial_var_noise(50) {
231 initial_e[0][0] = 100;
232 initial_e[1][1] = 1e-1;
233 initial_e[0][1] = initial_e[1][0] = 0;
234 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800235 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800236 }
237 double initial_slope;
238 double initial_offset;
239 double initial_e[2][2];
240 double initial_process_noise[2];
241 double initial_avg_noise;
242 double initial_var_noise;
243};
244
isheriff6b4b5f32016-06-08 00:24:21 -0700245// Minimum and maximum playout delay values from capture to render.
246// These are best effort values.
247//
248// A value < 0 indicates no change from previous valid value.
249//
250// min = max = 0 indicates that the receiver should try and render
251// frame as soon as possible.
252//
253// min = x, max = y indicates that the receiver is free to adapt
254// in the range (x, y) based on network jitter.
255//
256// Note: Given that this gets embedded in a union, it is up-to the owner to
257// initialize these values.
258struct PlayoutDelay {
259 int min_ms;
260 int max_ms;
261};
262
niklase@google.com470e71d2011-07-07 08:21:25 +0000263} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000264
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200265#endif // COMMON_TYPES_H_