blob: c6d4c948e07c1b51c4ef4c268c57fb1ed0f8016d [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
Erik Språng566124a2018-04-23 12:32:22 +020017// TODO(sprang): Remove this include when all usage includes it directly.
18#include "api/video/video_bitrate_allocation.h"
Niels Möller22b70ff2018-11-20 11:06:58 +010019// TODO(bugs.webrtc.org/7660): Delete include once downstream code is updated.
20#include "api/video/video_codec_type.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000022#if defined(_MSC_VER)
23// Disable "new behavior: elements of array will be default initialized"
24// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070025#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000026#endif
27
Peter Boström8b79b072016-02-26 16:31:37 +010028#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000029
niklase@google.com470e71d2011-07-07 08:21:25 +000030namespace webrtc {
31
pbos22993e12015-10-19 02:39:06 -070032enum FrameType {
33 kEmptyFrame = 0,
34 kAudioFrameSpeech = 1,
35 kAudioFrameCN = 2,
36 kVideoFrameKey = 3,
37 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000038};
39
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000040// Statistics for RTCP packet types.
41struct RtcpPacketTypeCounter {
42 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070043 : 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.org8098e072014-02-19 11:59:02 +000049
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.org2dd31342014-10-29 12:42:30 +000054 nack_requests += other.nack_requests;
55 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000056 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -070057 (other.first_packet_time_ms < first_packet_time_ms ||
58 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +000059 // Use oldest time.
60 first_packet_time_ms = other.first_packet_time_ms;
61 }
62 }
63
sprang07fb9be2016-02-24 07:55:00 -080064 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.orgd08d3892014-12-16 12:03:11 +000078 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
79 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000080 }
81
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000082 int UniqueNackRequestsInPercent() const {
83 if (nack_requests == 0) {
84 return 0;
85 }
solenberg634b86e2016-09-01 07:54:53 -070086 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
87 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +000088 }
89
solenberg634b86e2016-09-01 07:54:53 -070090 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.org2dd31342014-10-29 12:42:30 +000095 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000096};
97
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000098class RtcpPacketTypeCounterObserver {
99 public:
100 virtual ~RtcpPacketTypeCounterObserver() {}
101 virtual void RtcpPacketTypesCounterUpdated(
102 uint32_t ssrc,
103 const RtcpPacketTypeCounter& packet_counter) = 0;
104};
105
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000106// Callback, used to notify an observer whenever new rates have been estimated.
107class BitrateStatisticsObserver {
108 public:
109 virtual ~BitrateStatisticsObserver() {}
110
sprangcd349d92016-07-13 09:11:28 -0700111 virtual void Notify(uint32_t total_bitrate_bps,
112 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000113 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000114};
115
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000116struct FrameCounts {
117 FrameCounts() : key_frames(0), delta_frames(0) {}
118 int key_frames;
119 int delta_frames;
120};
121
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000122// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000123class FrameCountObserver {
124 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000125 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000126 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
127 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000128};
129
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000130// Callback, used to notify an observer whenever the send-side delay is updated.
131class 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
asapersson35151f32016-05-02 23:44:01 -0700139// 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.
143class 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
michaelt4da30442016-11-17 01:38:43 -0800151// Callback, used to notify an observer when the overhead per packet
152// has changed.
153class OverheadObserver {
154 public:
155 virtual ~OverheadObserver() = default;
156 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
157};
158
niklase@google.com470e71d2011-07-07 08:21:25 +0000159// RTP
solenberg634b86e2016-09-01 07:54:53 -0700160enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
niklase@google.com470e71d2011-07-07 08:21:25 +0000162// ==================================================================
163// Video specific types
164// ==================================================================
165
nisseeb44b392017-04-28 07:18:05 -0700166// TODO(nisse): Delete, and switch to fourcc values everywhere?
167// Supported video types.
168enum 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.com470e71d2011-07-07 08:21:25 +0000185};
186
magjede69a1a92016-11-25 10:06:31 -0800187// TODO(magjed): Move this and other H264 related classes out to their own file.
188namespace H264 {
189
190enum Profile {
191 kProfileConstrainedBaseline,
192 kProfileBaseline,
193 kProfileMain,
194 kProfileConstrainedHigh,
195 kProfileHigh,
196};
197
198} // namespace H264
199
Sergey Silkin13e74342018-03-02 12:28:00 +0100200struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100201 bool operator==(const SpatialLayer& other) const;
202 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
203
solenberg634b86e2016-09-01 07:54:53 -0700204 unsigned short width;
205 unsigned short height;
Sergey Silkin1946a3f2018-08-22 11:42:16 +0200206 float maxFramerate; // fps.
solenberg634b86e2016-09-01 07:54:53 -0700207 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 Hampsonf6464c92018-01-17 13:55:14 -0800212 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000213};
214
Sergey Silkin13e74342018-03-02 12:28:00 +0100215// Simulcast is when the same stream is encoded multiple times with different
216// settings such as resolution.
217typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800218
stefan64c0a0a2015-11-27 01:02:31 -0800219// 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
terelius84f83f82016-12-27 10:43:01 -0800222// 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
stefan64c0a0a2015-11-27 01:02:31 -0800225struct OverUseDetectorOptions {
226 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700227 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800228 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;
stefan1069cac2016-03-10 05:13:21 -0800237 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800238 }
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
isheriff6b4b5f32016-06-08 00:24:21 -0700247// 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.
260struct PlayoutDelay {
261 int min_ms;
262 int max_ms;
263};
264
niklase@google.com470e71d2011-07-07 08:21:25 +0000265} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000266
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200267#endif // COMMON_TYPES_H_