blob: f7170940928fe1acdaaca3e646e087388af2c5cb [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
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000014#include <stddef.h>
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000015#include <string.h>
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000016#include <string>
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000017#include <vector>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/array_view.h"
20#include "api/optional.h"
Erik Språng566124a2018-04-23 12:32:22 +020021// TODO(sprang): Remove this include when all usage includes it directly.
22#include "api/video/video_bitrate_allocation.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/checks.h"
24#include "rtc_base/deprecation.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020025#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000026
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000027#if defined(_MSC_VER)
28// Disable "new behavior: elements of array will be default initialized"
29// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070030#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000031#endif
32
niklase@google.com470e71d2011-07-07 08:21:25 +000033#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000034#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:25 +000035#endif
36
Peter Boström8b79b072016-02-26 16:31:37 +010037#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000038
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000039#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +000040// Compares two strings without regard to case.
41#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
42// Compares characters of two strings without regard to case.
43#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
44#else
45#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
46#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
47#endif
48
niklase@google.com470e71d2011-07-07 08:21:25 +000049namespace webrtc {
50
pbos22993e12015-10-19 02:39:06 -070051enum FrameType {
52 kEmptyFrame = 0,
53 kAudioFrameSpeech = 1,
54 kAudioFrameCN = 2,
55 kVideoFrameKey = 3,
56 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000057};
58
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000059// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000060struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000061 RtcpStatistics()
solenberg634b86e2016-09-01 07:54:53 -070062 : fraction_lost(0),
srte186d9c32017-08-04 05:03:53 -070063 packets_lost(0),
64 extended_highest_sequence_number(0),
solenberg634b86e2016-09-01 07:54:53 -070065 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000066
67 uint8_t fraction_lost;
srte186d9c32017-08-04 05:03:53 -070068 union {
Harald Alvestrandc7c41912017-12-08 09:59:34 +010069 int32_t packets_lost; // Defined as a 24 bit signed integer in RTCP
srte186d9c32017-08-04 05:03:53 -070070 RTC_DEPRECATED uint32_t cumulative_lost;
71 };
72 union {
73 uint32_t extended_highest_sequence_number;
74 RTC_DEPRECATED uint32_t extended_max_sequence_number;
75 };
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000076 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000077};
78
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000079class RtcpStatisticsCallback {
80 public:
81 virtual ~RtcpStatisticsCallback() {}
82
83 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
84 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000085 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000086};
87
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000088// Statistics for RTCP packet types.
89struct RtcpPacketTypeCounter {
90 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -070091 : first_packet_time_ms(-1),
92 nack_packets(0),
93 fir_packets(0),
94 pli_packets(0),
95 nack_requests(0),
96 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +000097
98 void Add(const RtcpPacketTypeCounter& other) {
99 nack_packets += other.nack_packets;
100 fir_packets += other.fir_packets;
101 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000102 nack_requests += other.nack_requests;
103 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000104 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -0700105 (other.first_packet_time_ms < first_packet_time_ms ||
106 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000107 // Use oldest time.
108 first_packet_time_ms = other.first_packet_time_ms;
109 }
110 }
111
sprang07fb9be2016-02-24 07:55:00 -0800112 void Subtract(const RtcpPacketTypeCounter& other) {
113 nack_packets -= other.nack_packets;
114 fir_packets -= other.fir_packets;
115 pli_packets -= other.pli_packets;
116 nack_requests -= other.nack_requests;
117 unique_nack_requests -= other.unique_nack_requests;
118 if (other.first_packet_time_ms != -1 &&
119 (other.first_packet_time_ms > first_packet_time_ms ||
120 first_packet_time_ms == -1)) {
121 // Use youngest time.
122 first_packet_time_ms = other.first_packet_time_ms;
123 }
124 }
125
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000126 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
127 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000128 }
129
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000130 int UniqueNackRequestsInPercent() const {
131 if (nack_requests == 0) {
132 return 0;
133 }
solenberg634b86e2016-09-01 07:54:53 -0700134 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
135 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000136 }
137
solenberg634b86e2016-09-01 07:54:53 -0700138 int64_t first_packet_time_ms; // Time when first packet is sent/received.
139 uint32_t nack_packets; // Number of RTCP NACK packets.
140 uint32_t fir_packets; // Number of RTCP FIR packets.
141 uint32_t pli_packets; // Number of RTCP PLI packets.
142 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000143 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000144};
145
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000146class RtcpPacketTypeCounterObserver {
147 public:
148 virtual ~RtcpPacketTypeCounterObserver() {}
149 virtual void RtcpPacketTypesCounterUpdated(
150 uint32_t ssrc,
151 const RtcpPacketTypeCounter& packet_counter) = 0;
152};
153
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000154// Callback, used to notify an observer whenever new rates have been estimated.
155class BitrateStatisticsObserver {
156 public:
157 virtual ~BitrateStatisticsObserver() {}
158
sprangcd349d92016-07-13 09:11:28 -0700159 virtual void Notify(uint32_t total_bitrate_bps,
160 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000161 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000162};
163
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000164struct FrameCounts {
165 FrameCounts() : key_frames(0), delta_frames(0) {}
166 int key_frames;
167 int delta_frames;
168};
169
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000170// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000171class FrameCountObserver {
172 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000173 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000174 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
175 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000176};
177
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000178// Callback, used to notify an observer whenever the send-side delay is updated.
179class SendSideDelayObserver {
180 public:
181 virtual ~SendSideDelayObserver() {}
182 virtual void SendSideDelayUpdated(int avg_delay_ms,
183 int max_delay_ms,
184 uint32_t ssrc) = 0;
185};
186
asapersson35151f32016-05-02 23:44:01 -0700187// Callback, used to notify an observer whenever a packet is sent to the
188// transport.
189// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
190// Remove SendSideDelayObserver once possible.
191class SendPacketObserver {
192 public:
193 virtual ~SendPacketObserver() {}
194 virtual void OnSendPacket(uint16_t packet_id,
195 int64_t capture_time_ms,
196 uint32_t ssrc) = 0;
197};
198
michaelt4da30442016-11-17 01:38:43 -0800199// Callback, used to notify an observer when the overhead per packet
200// has changed.
201class OverheadObserver {
202 public:
203 virtual ~OverheadObserver() = default;
204 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
205};
206
niklase@google.com470e71d2011-07-07 08:21:25 +0000207// ==================================================================
208// Voice specific types
209// ==================================================================
210
211// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000212struct CodecInst {
213 int pltype;
214 char plname[RTP_PAYLOAD_NAME_SIZE];
215 int plfreq;
216 int pacsize;
Peter Kasting69558702016-01-12 16:26:35 -0800217 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000218 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
219
220 bool operator==(const CodecInst& other) const {
221 return pltype == other.pltype &&
222 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenberg634b86e2016-09-01 07:54:53 -0700223 plfreq == other.plfreq && pacsize == other.pacsize &&
224 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000225 }
226
solenberg634b86e2016-09-01 07:54:53 -0700227 bool operator!=(const CodecInst& other) const { return !(*this == other); }
niklase@google.com470e71d2011-07-07 08:21:25 +0000228};
229
niklase@google.com470e71d2011-07-07 08:21:25 +0000230// RTP
solenberg634b86e2016-09-01 07:54:53 -0700231enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
solenberg634b86e2016-09-01 07:54:53 -0700233// NETEQ statistics.
234struct NetworkStatistics {
235 // current jitter buffer size in ms
236 uint16_t currentBufferSize;
237 // preferred (optimal) buffer size in ms
238 uint16_t preferredBufferSize;
239 // adding extra delay due to "peaky jitter"
240 bool jitterPeaksFound;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200241 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
242 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton2dbc69f2017-08-24 17:15:13 -0700243 uint64_t totalSamplesReceived;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700244 uint64_t concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200245 uint64_t concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200246 uint64_t jitterBufferDelayMs;
247 // Stats below DO NOT correspond directly to anything in the WebRTC stats
solenberg634b86e2016-09-01 07:54:53 -0700248 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
249 uint16_t currentPacketLossRate;
250 // Late loss rate; fraction between 0 and 1, scaled to Q14.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200251 union {
252 RTC_DEPRECATED uint16_t currentDiscardRate;
253 };
solenberg634b86e2016-09-01 07:54:53 -0700254 // fraction (of original stream) of synthesized audio inserted through
255 // expansion (in Q14)
256 uint16_t currentExpandRate;
257 // fraction (of original stream) of synthesized speech inserted through
258 // expansion (in Q14)
259 uint16_t currentSpeechExpandRate;
260 // fraction of synthesized speech inserted through pre-emptive expansion
261 // (in Q14)
262 uint16_t currentPreemptiveRate;
263 // fraction of data removed through acceleration (in Q14)
264 uint16_t currentAccelerateRate;
265 // fraction of data coming from secondary decoding (in Q14)
266 uint16_t currentSecondaryDecodedRate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200267 // Fraction of secondary data, including FEC and RED, that is discarded (in
268 // Q14). Discarding of secondary data can be caused by the reception of the
269 // primary data, obsoleting the secondary data. It can also be caused by early
270 // or late arrival of secondary data.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200271 uint16_t currentSecondaryDiscardedRate;
solenberg634b86e2016-09-01 07:54:53 -0700272 // clock-drift in parts-per-million (negative or positive)
273 int32_t clockDriftPPM;
274 // average packet waiting time in the jitter buffer (ms)
275 int meanWaitingTimeMs;
276 // median packet waiting time in the jitter buffer (ms)
277 int medianWaitingTimeMs;
278 // min packet waiting time in the jitter buffer (ms)
279 int minWaitingTimeMs;
280 // max packet waiting time in the jitter buffer (ms)
281 int maxWaitingTimeMs;
282 // added samples in off mode due to packet loss
283 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25 +0000284};
285
wu@webrtc.org24301a62013-12-13 19:17:43 +0000286// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
287struct AudioDecodingCallStats {
288 AudioDecodingCallStats()
289 : calls_to_silence_generator(0),
290 calls_to_neteq(0),
291 decoded_normal(0),
292 decoded_plc(0),
293 decoded_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700294 decoded_plc_cng(0),
295 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43 +0000296
297 int calls_to_silence_generator; // Number of calls where silence generated,
298 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 07:54:53 -0700299 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000300 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 07:54:53 -0700301 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000302 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
303 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 01:47:12 -0700304 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000305};
306
niklase@google.com470e71d2011-07-07 08:21:25 +0000307// ==================================================================
308// Video specific types
309// ==================================================================
310
nisseeb44b392017-04-28 07:18:05 -0700311// TODO(nisse): Delete, and switch to fourcc values everywhere?
312// Supported video types.
313enum class VideoType {
314 kUnknown,
315 kI420,
316 kIYUV,
317 kRGB24,
318 kABGR,
319 kARGB,
320 kARGB4444,
321 kRGB565,
322 kARGB1555,
323 kYUY2,
324 kYV12,
325 kUYVY,
326 kMJPEG,
327 kNV21,
328 kNV12,
329 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25 +0000330};
331
332// Video codec
solenberg634b86e2016-09-01 07:54:53 -0700333enum VideoCodecComplexity {
334 kComplexityNormal = 0,
335 kComplexityHigh = 1,
336 kComplexityHigher = 2,
337 kComplexityMax = 3
niklase@google.com470e71d2011-07-07 08:21:25 +0000338};
339
niklase@google.com470e71d2011-07-07 08:21:25 +0000340// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000341struct VideoCodecVP8 {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100342 bool operator==(const VideoCodecVP8& other) const;
343 bool operator!=(const VideoCodecVP8& other) const {
344 return !(*this == other);
345 }
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000346 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 07:54:53 -0700347 unsigned char numberOfTemporalLayers;
348 bool denoisingOn;
solenberg634b86e2016-09-01 07:54:53 -0700349 bool automaticResizeOn;
350 bool frameDroppingOn;
351 int keyFrameInterval;
niklase@google.com470e71d2011-07-07 08:21:25 +0000352};
353
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200354enum class InterLayerPredMode {
355 kOn, // Allow inter-layer prediction for all frames.
356 // Frame of low spatial layer can be used for
357 // prediction of next spatial layer frame.
358 kOff, // Encoder produces independent spatial layers.
359 kOnKeyPic // Allow inter-layer prediction only for frames
360 // within key picture.
361};
362
asaperssona9455ab2015-07-31 06:10:09 -0700363// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000364struct VideoCodecVP9 {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100365 bool operator==(const VideoCodecVP9& other) const;
366 bool operator!=(const VideoCodecVP9& other) const {
367 return !(*this == other);
368 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000369 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 07:54:53 -0700370 unsigned char numberOfTemporalLayers;
371 bool denoisingOn;
372 bool frameDroppingOn;
373 int keyFrameInterval;
374 bool adaptiveQpMode;
375 bool automaticResizeOn;
376 unsigned char numberOfSpatialLayers;
377 bool flexibleMode;
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200378 InterLayerPredMode interLayerPred;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000379};
380
magjede69a1a92016-11-25 10:06:31 -0800381// TODO(magjed): Move this and other H264 related classes out to their own file.
382namespace H264 {
383
384enum Profile {
385 kProfileConstrainedBaseline,
386 kProfileBaseline,
387 kProfileMain,
388 kProfileConstrainedHigh,
389 kProfileHigh,
390};
391
392} // namespace H264
393
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000394// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000395struct VideoCodecH264 {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100396 bool operator==(const VideoCodecH264& other) const;
397 bool operator!=(const VideoCodecH264& other) const {
398 return !(*this == other);
399 }
solenberg634b86e2016-09-01 07:54:53 -0700400 bool frameDroppingOn;
401 int keyFrameInterval;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000402 // These are NULL/0 if not externally negotiated.
403 const uint8_t* spsData;
solenberg634b86e2016-09-01 07:54:53 -0700404 size_t spsLen;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000405 const uint8_t* ppsData;
solenberg634b86e2016-09-01 07:54:53 -0700406 size_t ppsLen;
magjede69a1a92016-11-25 10:06:31 -0800407 H264::Profile profile;
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000408};
409
niklase@google.com470e71d2011-07-07 08:21:25 +0000410// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000411enum VideoCodecType {
412 kVideoCodecVP8,
413 kVideoCodecVP9,
414 kVideoCodecH264,
415 kVideoCodecI420,
416 kVideoCodecRED,
417 kVideoCodecULPFEC,
brandtr87d7d772016-11-07 03:03:41 -0800418 kVideoCodecFlexfec,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000419 kVideoCodecGeneric,
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800420 kVideoCodecMultiplex,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000421 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25 +0000422};
423
Erik Språng08127a92016-11-16 16:41:30 +0100424// Translates from name of codec to codec type and vice versa.
kthelgason1cdddc92017-08-24 03:52:48 -0700425const char* CodecTypeToPayloadString(VideoCodecType type);
426VideoCodecType PayloadStringToCodecType(const std::string& name);
Erik Språng08127a92016-11-16 16:41:30 +0100427
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000428union VideoCodecUnion {
solenberg634b86e2016-09-01 07:54:53 -0700429 VideoCodecVP8 VP8;
430 VideoCodecVP9 VP9;
431 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25 +0000432};
433
Sergey Silkin13e74342018-03-02 12:28:00 +0100434struct SpatialLayer {
Niels Möllerdef1ef52018-03-19 13:48:44 +0100435 bool operator==(const SpatialLayer& other) const;
436 bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
437
solenberg634b86e2016-09-01 07:54:53 -0700438 unsigned short width;
439 unsigned short height;
440 unsigned char numberOfTemporalLayers;
441 unsigned int maxBitrate; // kilobits/sec.
442 unsigned int targetBitrate; // kilobits/sec.
443 unsigned int minBitrate; // kilobits/sec.
444 unsigned int qpMax; // minimum quality
Seth Hampsonf6464c92018-01-17 13:55:14 -0800445 bool active; // encoded and sent.
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000446};
447
Sergey Silkin13e74342018-03-02 12:28:00 +0100448// Simulcast is when the same stream is encoded multiple times with different
449// settings such as resolution.
450typedef SpatialLayer SimulcastStream;
sprangce4aef12015-11-02 07:23:20 -0800451
solenberg634b86e2016-09-01 07:54:53 -0700452enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000453
niklase@google.com470e71d2011-07-07 08:21:25 +0000454// Common video codec properties
hta257dc392016-10-25 09:05:06 -0700455class VideoCodec {
456 public:
457 VideoCodec();
458
459 // Public variables. TODO(hta): Make them private with accessors.
solenberg634b86e2016-09-01 07:54:53 -0700460 VideoCodecType codecType;
solenberg634b86e2016-09-01 07:54:53 -0700461 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000462
solenberg634b86e2016-09-01 07:54:53 -0700463 unsigned short width;
464 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25 +0000465
solenberg634b86e2016-09-01 07:54:53 -0700466 unsigned int startBitrate; // kilobits/sec.
467 unsigned int maxBitrate; // kilobits/sec.
468 unsigned int minBitrate; // kilobits/sec.
469 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52 +0000470
Stefan Holmer144475b2017-03-10 15:08:26 +0100471 uint32_t maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000472
Seth Hampsonf6464c92018-01-17 13:55:14 -0800473 // This enables/disables encoding and sending when there aren't multiple
474 // simulcast streams,by allocating 0 bitrate if inactive.
475 bool active;
476
solenberg634b86e2016-09-01 07:54:53 -0700477 unsigned int qpMax;
478 unsigned char numberOfSimulcastStreams;
479 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 07:23:20 -0800480 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000481
solenberg634b86e2016-09-01 07:54:53 -0700482 VideoCodecMode mode;
483 bool expect_encode_from_texture;
andresp@webrtc.org185bae42013-05-14 08:02:25 +0000484
ilnik04f4d122017-06-19 07:18:55 -0700485 // Timing frames configuration. There is delay of delay_ms between two
486 // consequent timing frames, excluding outliers. Frame is always made a
487 // timing frame if it's at least outlier_ratio in percent of "ideal" average
488 // frame given bitrate and framerate, i.e. if it's bigger than
489 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
490 // frames will not be sent too often usually. Yet large frames will always
491 // have timing information for debug purposes because they are more likely to
492 // cause extra delays.
493 struct TimingFrameTriggerThresholds {
494 int64_t delay_ms;
495 uint16_t outlier_ratio_percent;
496 } timing_frame_thresholds;
497
Peter Boström7b971e72016-01-19 16:26:16 +0100498 bool operator==(const VideoCodec& other) const = delete;
499 bool operator!=(const VideoCodec& other) const = delete;
hta257dc392016-10-25 09:05:06 -0700500
501 // Accessors for codec specific information.
502 // There is a const version of each that returns a reference,
503 // and a non-const version that returns a pointer, in order
504 // to allow modification of the parameters.
505 VideoCodecVP8* VP8();
506 const VideoCodecVP8& VP8() const;
507 VideoCodecVP9* VP9();
508 const VideoCodecVP9& VP9() const;
509 VideoCodecH264* H264();
510 const VideoCodecH264& H264() const;
511
hta527d3472016-11-16 23:23:04 -0800512 private:
hta257dc392016-10-25 09:05:06 -0700513 // TODO(hta): Consider replacing the union with a pointer type.
514 // This will allow removing the VideoCodec* types from this file.
hta527d3472016-11-16 23:23:04 -0800515 VideoCodecUnion codec_specific_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000516};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000517
Erik Språng566124a2018-04-23 12:32:22 +0200518// TODO(sprang): Remove this when downstream projects have been updated.
519using BitrateAllocation = VideoBitrateAllocation;
Erik Språng08127a92016-11-16 16:41:30 +0100520
stefan64c0a0a2015-11-27 01:02:31 -0800521// Bandwidth over-use detector options. These are used to drive
522// experimentation with bandwidth estimation parameters.
523// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800524// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
525// default constructed state. Can we move the relevant variables into that
526// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800527struct OverUseDetectorOptions {
528 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700529 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800530 initial_offset(0),
531 initial_e(),
532 initial_process_noise(),
533 initial_avg_noise(0.0),
534 initial_var_noise(50) {
535 initial_e[0][0] = 100;
536 initial_e[1][1] = 1e-1;
537 initial_e[0][1] = initial_e[1][0] = 0;
538 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800539 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800540 }
541 double initial_slope;
542 double initial_offset;
543 double initial_e[2][2];
544 double initial_process_noise[2];
545 double initial_avg_noise;
546 double initial_var_noise;
547};
548
wu@webrtc.orga9890802013-12-13 00:21:03 +0000549// This structure will have the information about when packet is actually
550// received by socket.
551struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000552 PacketTime() : timestamp(-1), not_before(-1) {}
553 PacketTime(int64_t timestamp, int64_t not_before)
solenberg634b86e2016-09-01 07:54:53 -0700554 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orga9890802013-12-13 00:21:03 +0000555
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000556 int64_t timestamp; // Receive time after socket delivers the data.
557 int64_t not_before; // Earliest possible time the data could have arrived,
558 // indicating the potential error in the |timestamp|
559 // value,in case the system is busy.
560 // For example, the time of the last select() call.
561 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000562};
563
isheriff6b4b5f32016-06-08 00:24:21 -0700564// Minimum and maximum playout delay values from capture to render.
565// These are best effort values.
566//
567// A value < 0 indicates no change from previous valid value.
568//
569// min = max = 0 indicates that the receiver should try and render
570// frame as soon as possible.
571//
572// min = x, max = y indicates that the receiver is free to adapt
573// in the range (x, y) based on network jitter.
574//
575// Note: Given that this gets embedded in a union, it is up-to the owner to
576// initialize these values.
577struct PlayoutDelay {
578 int min_ms;
579 int max_ms;
580};
581
niklase@google.com470e71d2011-07-07 08:21:25 +0000582} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000583
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200584#endif // COMMON_TYPES_H_