blob: da481531d681fae01acbeac096843638c1a8147d [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"
Niels Möllerc936cb62019-03-19 14:10:16 +010019// 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.com470e71d2011-07-07 08:21:25 +000022
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000023#if defined(_MSC_VER)
24// Disable "new behavior: elements of array will be default initialized"
25// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070026#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000027#endif
28
niklase@google.com470e71d2011-07-07 08:21:25 +000029namespace webrtc {
30
Niels Möller87e2d782019-03-07 10:18:23 +010031// 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.
33enum FrameTypeDeprecated {
pbos22993e12015-10-19 02:39:06 -070034 kEmptyFrame = 0,
35 kAudioFrameSpeech = 1,
36 kAudioFrameCN = 2,
37 kVideoFrameKey = 3,
38 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000039};
40
Niels Möller87e2d782019-03-07 10:18:23 +010041// Can't use RTC_DEPRECATED until Chromium is updated.
42typedef FrameTypeDeprecated FrameType;
43
Niels Möller87e2d782019-03-07 10:18:23 +010044using VideoFrameType = FrameTypeDeprecated;
45
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000046// Statistics for RTCP packet types.
47struct RtcpPacketTypeCounter {
48 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070049 : 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.org8098e072014-02-19 11:59:02 +000055
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.org2dd31342014-10-29 12:42:30 +000060 nack_requests += other.nack_requests;
61 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000062 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -070063 (other.first_packet_time_ms < first_packet_time_ms ||
64 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000065 // Use oldest time.
66 first_packet_time_ms = other.first_packet_time_ms;
67 }
68 }
69
sprang07fb9be2016-02-24 07:55:00 -080070 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.orgd08d3892014-12-16 12:03:11 +000084 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
85 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000086 }
87
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000088 int UniqueNackRequestsInPercent() const {
89 if (nack_requests == 0) {
90 return 0;
91 }
solenberg634b86e2016-09-01 07:54:53 -070092 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
93 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000094 }
95
solenberg634b86e2016-09-01 07:54:53 -070096 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.org2dd31342014-10-29 12:42:30 +0000101 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000102};
103
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000104class RtcpPacketTypeCounterObserver {
105 public:
106 virtual ~RtcpPacketTypeCounterObserver() {}
107 virtual void RtcpPacketTypesCounterUpdated(
108 uint32_t ssrc,
109 const RtcpPacketTypeCounter& packet_counter) = 0;
110};
111
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000112// Callback, used to notify an observer whenever new rates have been estimated.
113class BitrateStatisticsObserver {
114 public:
115 virtual ~BitrateStatisticsObserver() {}
116
sprangcd349d92016-07-13 09:11:28 -0700117 virtual void Notify(uint32_t total_bitrate_bps,
118 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000119 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000120};
121
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000122struct FrameCounts {
123 FrameCounts() : key_frames(0), delta_frames(0) {}
124 int key_frames;
125 int delta_frames;
126};
127
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000128// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000129class FrameCountObserver {
130 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000131 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000132 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
133 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000134};
135
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000136// Callback, used to notify an observer whenever the send-side delay is updated.
137class 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
asapersson35151f32016-05-02 23:44:01 -0700145// 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.
149class 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
michaelt4da30442016-11-17 01:38:43 -0800157// Callback, used to notify an observer when the overhead per packet
158// has changed.
159class OverheadObserver {
160 public:
161 virtual ~OverheadObserver() = default;
162 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
163};
164
niklase@google.com470e71d2011-07-07 08:21:25 +0000165// RTP
solenberg634b86e2016-09-01 07:54:53 -0700166enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
niklase@google.com470e71d2011-07-07 08:21:25 +0000168// ==================================================================
169// Video specific types
170// ==================================================================
171
nisseeb44b392017-04-28 07:18:05 -0700172// TODO(nisse): Delete, and switch to fourcc values everywhere?
173// Supported video types.
174enum 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.com470e71d2011-07-07 08:21:25 +0000191};
192
magjede69a1a92016-11-25 10:06:31 -0800193// TODO(magjed): Move this and other H264 related classes out to their own file.
194namespace H264 {
195
196enum Profile {
197 kProfileConstrainedBaseline,
198 kProfileBaseline,
199 kProfileMain,
200 kProfileConstrainedHigh,
201 kProfileHigh,
202};
203
204} // namespace H264
205
Sergey Silkin13e74342018-03-02 12:28:00 +0100206struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100207 bool operator==(const SpatialLayer& other) const;
208 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
209
solenberg634b86e2016-09-01 07:54:53 -0700210 unsigned short width;
211 unsigned short height;
Sergey Silkin1946a3f2018-08-22 11:42:16 +0200212 float maxFramerate; // fps.
solenberg634b86e2016-09-01 07:54:53 -0700213 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 Hampsonf6464c92018-01-17 13:55:14 -0800218 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000219};
220
Sergey Silkin13e74342018-03-02 12:28:00 +0100221// Simulcast is when the same stream is encoded multiple times with different
222// settings such as resolution.
223typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800224
stefan64c0a0a2015-11-27 01:02:31 -0800225// 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
terelius84f83f82016-12-27 10:43:01 -0800228// 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
stefan64c0a0a2015-11-27 01:02:31 -0800231struct OverUseDetectorOptions {
232 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700233 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800234 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;
stefan1069cac2016-03-10 05:13:21 -0800243 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800244 }
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
isheriff6b4b5f32016-06-08 00:24:21 -0700253// 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.
266struct PlayoutDelay {
267 int min_ms;
268 int max_ms;
269};
270
niklase@google.com470e71d2011-07-07 08:21:25 +0000271} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000272
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200273#endif // COMMON_TYPES_H_