blob: 9f1ad8f9f79da7251d4ad62d8b2f4c82991c6598 [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>
kwiberg5bf4e082016-12-19 06:04:04 -080016#include <ostream>
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000017#include <string>
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000018#include <vector>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/array_view.h"
21#include "api/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/checks.h"
23#include "rtc_base/deprecation.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020024#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000025
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000026#if defined(_MSC_VER)
27// Disable "new behavior: elements of array will be default initialized"
28// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 07:54:53 -070029#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000030#endif
31
kwiberg77eab702016-09-28 17:42:01 -070032#if defined(WEBRTC_EXPORT)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000033#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg77eab702016-09-28 17:42:01 -070034#elif defined(WEBRTC_DLL)
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000035#define WEBRTC_DLLEXPORT _declspec(dllimport)
niklase@google.com470e71d2011-07-07 08:21:25 +000036#else
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000037#define WEBRTC_DLLEXPORT
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39
40#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000041#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:25 +000042#endif
43
Peter Boström8b79b072016-02-26 16:31:37 +010044#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000045
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000046#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +000047// Compares two strings without regard to case.
48#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
49// Compares characters of two strings without regard to case.
50#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
51#else
52#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
53#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
54#endif
55
niklase@google.com470e71d2011-07-07 08:21:25 +000056namespace webrtc {
57
tommia6219cc2016-06-15 10:30:14 -070058class RewindableStream {
59 public:
60 virtual ~RewindableStream() {}
61 virtual int Rewind() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000062};
63
tommia6219cc2016-06-15 10:30:14 -070064class InStream : public RewindableStream {
65 public:
66 // Reads |len| bytes from file to |buf|. Returns the number of bytes read
67 // or -1 on error.
68 virtual int Read(void* buf, size_t len) = 0;
69};
70
71class OutStream : public RewindableStream {
72 public:
73 // Writes |len| bytes from |buf| to file. The actual writing may happen
74 // some time later. Call Flush() to force a write.
75 virtual bool Write(const void* buf, size_t len) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000076};
77
Niels Möller4f6b6c22017-12-01 11:17:32 +010078// For the deprecated MediaFile module.
solenberg634b86e2016-09-01 07:54:53 -070079enum FileFormats {
80 kFileFormatWavFile = 1,
solenberg634b86e2016-09-01 07:54:53 -070081 kFileFormatPcm16kHzFile = 7,
82 kFileFormatPcm8kHzFile = 8,
Minyue Li85a3b6b2017-09-01 14:36:33 +020083 kFileFormatPcm32kHzFile = 9,
niklase@google.com470e71d2011-07-07 08:21:25 +000084};
85
pbos22993e12015-10-19 02:39:06 -070086enum FrameType {
87 kEmptyFrame = 0,
88 kAudioFrameSpeech = 1,
89 kAudioFrameCN = 2,
90 kVideoFrameKey = 3,
91 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +000092};
93
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +000094// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000095struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +000096 RtcpStatistics()
solenberg634b86e2016-09-01 07:54:53 -070097 : fraction_lost(0),
srte186d9c32017-08-04 05:03:53 -070098 packets_lost(0),
99 extended_highest_sequence_number(0),
solenberg634b86e2016-09-01 07:54:53 -0700100 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000101
102 uint8_t fraction_lost;
srte186d9c32017-08-04 05:03:53 -0700103 union {
Harald Alvestrandc7c41912017-12-08 09:59:34 +0100104 int32_t packets_lost; // Defined as a 24 bit signed integer in RTCP
srte186d9c32017-08-04 05:03:53 -0700105 RTC_DEPRECATED uint32_t cumulative_lost;
106 };
107 union {
108 uint32_t extended_highest_sequence_number;
109 RTC_DEPRECATED uint32_t extended_max_sequence_number;
110 };
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000111 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000112};
113
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000114class RtcpStatisticsCallback {
115 public:
116 virtual ~RtcpStatisticsCallback() {}
117
118 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
119 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000120 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000121};
122
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000123// Statistics for RTCP packet types.
124struct RtcpPacketTypeCounter {
125 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 07:54:53 -0700126 : first_packet_time_ms(-1),
127 nack_packets(0),
128 fir_packets(0),
129 pli_packets(0),
130 nack_requests(0),
131 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000132
133 void Add(const RtcpPacketTypeCounter& other) {
134 nack_packets += other.nack_packets;
135 fir_packets += other.fir_packets;
136 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000137 nack_requests += other.nack_requests;
138 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000139 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 07:54:53 -0700140 (other.first_packet_time_ms < first_packet_time_ms ||
141 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000142 // Use oldest time.
143 first_packet_time_ms = other.first_packet_time_ms;
144 }
145 }
146
sprang07fb9be2016-02-24 07:55:00 -0800147 void Subtract(const RtcpPacketTypeCounter& other) {
148 nack_packets -= other.nack_packets;
149 fir_packets -= other.fir_packets;
150 pli_packets -= other.pli_packets;
151 nack_requests -= other.nack_requests;
152 unique_nack_requests -= other.unique_nack_requests;
153 if (other.first_packet_time_ms != -1 &&
154 (other.first_packet_time_ms > first_packet_time_ms ||
155 first_packet_time_ms == -1)) {
156 // Use youngest time.
157 first_packet_time_ms = other.first_packet_time_ms;
158 }
159 }
160
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000161 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
162 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000163 }
164
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000165 int UniqueNackRequestsInPercent() const {
166 if (nack_requests == 0) {
167 return 0;
168 }
solenberg634b86e2016-09-01 07:54:53 -0700169 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
170 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000171 }
172
solenberg634b86e2016-09-01 07:54:53 -0700173 int64_t first_packet_time_ms; // Time when first packet is sent/received.
174 uint32_t nack_packets; // Number of RTCP NACK packets.
175 uint32_t fir_packets; // Number of RTCP FIR packets.
176 uint32_t pli_packets; // Number of RTCP PLI packets.
177 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000178 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000179};
180
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000181class RtcpPacketTypeCounterObserver {
182 public:
183 virtual ~RtcpPacketTypeCounterObserver() {}
184 virtual void RtcpPacketTypesCounterUpdated(
185 uint32_t ssrc,
186 const RtcpPacketTypeCounter& packet_counter) = 0;
187};
188
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000189// Rate statistics for a stream.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000190struct BitrateStatistics {
sprangcd349d92016-07-13 09:11:28 -0700191 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000192
solenberg634b86e2016-09-01 07:54:53 -0700193 uint32_t bitrate_bps; // Bitrate in bits per second.
194 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000195};
196
197// Callback, used to notify an observer whenever new rates have been estimated.
198class BitrateStatisticsObserver {
199 public:
200 virtual ~BitrateStatisticsObserver() {}
201
sprangcd349d92016-07-13 09:11:28 -0700202 virtual void Notify(uint32_t total_bitrate_bps,
203 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000204 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000205};
206
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000207struct FrameCounts {
208 FrameCounts() : key_frames(0), delta_frames(0) {}
209 int key_frames;
210 int delta_frames;
211};
212
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000213// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000214class FrameCountObserver {
215 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000216 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000217 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
218 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000219};
220
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000221// Callback, used to notify an observer whenever the send-side delay is updated.
222class SendSideDelayObserver {
223 public:
224 virtual ~SendSideDelayObserver() {}
225 virtual void SendSideDelayUpdated(int avg_delay_ms,
226 int max_delay_ms,
227 uint32_t ssrc) = 0;
228};
229
asapersson35151f32016-05-02 23:44:01 -0700230// Callback, used to notify an observer whenever a packet is sent to the
231// transport.
232// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
233// Remove SendSideDelayObserver once possible.
234class SendPacketObserver {
235 public:
236 virtual ~SendPacketObserver() {}
237 virtual void OnSendPacket(uint16_t packet_id,
238 int64_t capture_time_ms,
239 uint32_t ssrc) = 0;
240};
241
michaelt4da30442016-11-17 01:38:43 -0800242// Callback, used to notify an observer when the overhead per packet
243// has changed.
244class OverheadObserver {
245 public:
246 virtual ~OverheadObserver() = default;
247 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
248};
249
niklase@google.com470e71d2011-07-07 08:21:25 +0000250// ==================================================================
251// Voice specific types
252// ==================================================================
253
254// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000255struct CodecInst {
256 int pltype;
257 char plname[RTP_PAYLOAD_NAME_SIZE];
258 int plfreq;
259 int pacsize;
Peter Kasting69558702016-01-12 16:26:35 -0800260 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000261 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
262
263 bool operator==(const CodecInst& other) const {
264 return pltype == other.pltype &&
265 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenberg634b86e2016-09-01 07:54:53 -0700266 plfreq == other.plfreq && pacsize == other.pacsize &&
267 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000268 }
269
solenberg634b86e2016-09-01 07:54:53 -0700270 bool operator!=(const CodecInst& other) const { return !(*this == other); }
kwiberg5bf4e082016-12-19 06:04:04 -0800271
272 friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
273 os << "{pltype: " << ci.pltype;
274 os << ", plname: " << ci.plname;
275 os << ", plfreq: " << ci.plfreq;
276 os << ", pacsize: " << ci.pacsize;
277 os << ", channels: " << ci.channels;
278 os << ", rate: " << ci.rate << "}";
279 return os;
280 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000281};
282
niklase@google.com470e71d2011-07-07 08:21:25 +0000283// RTP
solenberg634b86e2016-09-01 07:54:53 -0700284enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
solenberg634b86e2016-09-01 07:54:53 -0700286enum PayloadFrequencies {
287 kFreq8000Hz = 8000,
288 kFreq16000Hz = 16000,
289 kFreq32000Hz = 32000
niklase@google.com470e71d2011-07-07 08:21:25 +0000290};
291
solenberg634b86e2016-09-01 07:54:53 -0700292// Degree of bandwidth reduction.
293enum VadModes {
294 kVadConventional = 0, // lowest reduction
295 kVadAggressiveLow,
296 kVadAggressiveMid,
297 kVadAggressiveHigh // highest reduction
niklase@google.com470e71d2011-07-07 08:21:25 +0000298};
299
solenberg634b86e2016-09-01 07:54:53 -0700300// NETEQ statistics.
301struct NetworkStatistics {
302 // current jitter buffer size in ms
303 uint16_t currentBufferSize;
304 // preferred (optimal) buffer size in ms
305 uint16_t preferredBufferSize;
306 // adding extra delay due to "peaky jitter"
307 bool jitterPeaksFound;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200308 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
309 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton2dbc69f2017-08-24 17:15:13 -0700310 uint64_t totalSamplesReceived;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700311 uint64_t concealedSamples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200312 uint64_t concealmentEvents;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200313 uint64_t jitterBufferDelayMs;
314 // Stats below DO NOT correspond directly to anything in the WebRTC stats
solenberg634b86e2016-09-01 07:54:53 -0700315 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
316 uint16_t currentPacketLossRate;
317 // Late loss rate; fraction between 0 and 1, scaled to Q14.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200318 union {
319 RTC_DEPRECATED uint16_t currentDiscardRate;
320 };
solenberg634b86e2016-09-01 07:54:53 -0700321 // fraction (of original stream) of synthesized audio inserted through
322 // expansion (in Q14)
323 uint16_t currentExpandRate;
324 // fraction (of original stream) of synthesized speech inserted through
325 // expansion (in Q14)
326 uint16_t currentSpeechExpandRate;
327 // fraction of synthesized speech inserted through pre-emptive expansion
328 // (in Q14)
329 uint16_t currentPreemptiveRate;
330 // fraction of data removed through acceleration (in Q14)
331 uint16_t currentAccelerateRate;
332 // fraction of data coming from secondary decoding (in Q14)
333 uint16_t currentSecondaryDecodedRate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200334 // Fraction of secondary data, including FEC and RED, that is discarded (in
335 // Q14). Discarding of secondary data can be caused by the reception of the
336 // primary data, obsoleting the secondary data. It can also be caused by early
337 // or late arrival of secondary data.
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200338 uint16_t currentSecondaryDiscardedRate;
solenberg634b86e2016-09-01 07:54:53 -0700339 // clock-drift in parts-per-million (negative or positive)
340 int32_t clockDriftPPM;
341 // average packet waiting time in the jitter buffer (ms)
342 int meanWaitingTimeMs;
343 // median packet waiting time in the jitter buffer (ms)
344 int medianWaitingTimeMs;
345 // min packet waiting time in the jitter buffer (ms)
346 int minWaitingTimeMs;
347 // max packet waiting time in the jitter buffer (ms)
348 int maxWaitingTimeMs;
349 // added samples in off mode due to packet loss
350 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25 +0000351};
352
wu@webrtc.org24301a62013-12-13 19:17:43 +0000353// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
354struct AudioDecodingCallStats {
355 AudioDecodingCallStats()
356 : calls_to_silence_generator(0),
357 calls_to_neteq(0),
358 decoded_normal(0),
359 decoded_plc(0),
360 decoded_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700361 decoded_plc_cng(0),
362 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43 +0000363
364 int calls_to_silence_generator; // Number of calls where silence generated,
365 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 07:54:53 -0700366 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000367 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 07:54:53 -0700368 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000369 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
370 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 01:47:12 -0700371 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43 +0000372};
373
niklase@google.com470e71d2011-07-07 08:21:25 +0000374// ==================================================================
375// Video specific types
376// ==================================================================
377
nisseeb44b392017-04-28 07:18:05 -0700378// TODO(nisse): Delete, and switch to fourcc values everywhere?
379// Supported video types.
380enum class VideoType {
381 kUnknown,
382 kI420,
383 kIYUV,
384 kRGB24,
385 kABGR,
386 kARGB,
387 kARGB4444,
388 kRGB565,
389 kARGB1555,
390 kYUY2,
391 kYV12,
392 kUYVY,
393 kMJPEG,
394 kNV21,
395 kNV12,
396 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25 +0000397};
398
399// Video codec
solenberg634b86e2016-09-01 07:54:53 -0700400enum { kPayloadNameSize = 32 };
401enum { kMaxSimulcastStreams = 4 };
sprangce4aef12015-11-02 07:23:20 -0800402enum { kMaxSpatialLayers = 5 };
solenberg634b86e2016-09-01 07:54:53 -0700403enum { kMaxTemporalStreams = 4 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
solenberg634b86e2016-09-01 07:54:53 -0700405enum VideoCodecComplexity {
406 kComplexityNormal = 0,
407 kComplexityHigh = 1,
408 kComplexityHigher = 2,
409 kComplexityMax = 3
niklase@google.com470e71d2011-07-07 08:21:25 +0000410};
411
stefan@webrtc.orgefd0a482011-12-29 10:12:35 +0000412enum VP8ResilienceMode {
413 kResilienceOff, // The stream produced by the encoder requires a
414 // recovery frame (typically a key frame) to be
415 // decodable after a packet loss.
416 kResilientStream, // A stream produced by the encoder is resilient to
417 // packet losses, but packets within a frame subsequent
418 // to a loss can't be decoded.
419 kResilientFrames // Same as kResilientStream but with added resilience
420 // within a frame.
421};
422
Peter Boström7b971e72016-01-19 16:26:16 +0100423class TemporalLayersFactory;
niklase@google.com470e71d2011-07-07 08:21:25 +0000424// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000425struct VideoCodecVP8 {
nisse3257b162017-03-21 01:54:13 -0700426 // TODO(nisse): Unused, delete?
solenberg634b86e2016-09-01 07:54:53 -0700427 bool pictureLossIndicationOn;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000428 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 07:54:53 -0700429 VP8ResilienceMode resilience;
430 unsigned char numberOfTemporalLayers;
431 bool denoisingOn;
432 bool errorConcealmentOn;
433 bool automaticResizeOn;
434 bool frameDroppingOn;
435 int keyFrameInterval;
Erik Språng08127a92016-11-16 16:41:30 +0100436 TemporalLayersFactory* tl_factory;
niklase@google.com470e71d2011-07-07 08:21:25 +0000437};
438
asaperssona9455ab2015-07-31 06:10:09 -0700439// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000440struct VideoCodecVP9 {
441 VideoCodecComplexity complexity;
asapersson15dcb382017-06-08 02:55:08 -0700442 bool resilienceOn;
solenberg634b86e2016-09-01 07:54:53 -0700443 unsigned char numberOfTemporalLayers;
444 bool denoisingOn;
445 bool frameDroppingOn;
446 int keyFrameInterval;
447 bool adaptiveQpMode;
448 bool automaticResizeOn;
449 unsigned char numberOfSpatialLayers;
450 bool flexibleMode;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000451};
452
magjede69a1a92016-11-25 10:06:31 -0800453// TODO(magjed): Move this and other H264 related classes out to their own file.
454namespace H264 {
455
456enum Profile {
457 kProfileConstrainedBaseline,
458 kProfileBaseline,
459 kProfileMain,
460 kProfileConstrainedHigh,
461 kProfileHigh,
462};
463
464} // namespace H264
465
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000466// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000467struct VideoCodecH264 {
solenberg634b86e2016-09-01 07:54:53 -0700468 bool frameDroppingOn;
469 int keyFrameInterval;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000470 // These are NULL/0 if not externally negotiated.
471 const uint8_t* spsData;
solenberg634b86e2016-09-01 07:54:53 -0700472 size_t spsLen;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000473 const uint8_t* ppsData;
solenberg634b86e2016-09-01 07:54:53 -0700474 size_t ppsLen;
magjede69a1a92016-11-25 10:06:31 -0800475 H264::Profile profile;
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000476};
477
niklase@google.com470e71d2011-07-07 08:21:25 +0000478// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000479enum VideoCodecType {
480 kVideoCodecVP8,
481 kVideoCodecVP9,
482 kVideoCodecH264,
483 kVideoCodecI420,
484 kVideoCodecRED,
485 kVideoCodecULPFEC,
brandtr87d7d772016-11-07 03:03:41 -0800486 kVideoCodecFlexfec,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000487 kVideoCodecGeneric,
Emircan Uysaler90612a62017-11-28 09:45:25 -0800488 kVideoCodecStereo,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000489 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25 +0000490};
491
Erik Språng08127a92016-11-16 16:41:30 +0100492// Translates from name of codec to codec type and vice versa.
kthelgason1cdddc92017-08-24 03:52:48 -0700493const char* CodecTypeToPayloadString(VideoCodecType type);
494VideoCodecType PayloadStringToCodecType(const std::string& name);
Erik Språng08127a92016-11-16 16:41:30 +0100495
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000496union VideoCodecUnion {
solenberg634b86e2016-09-01 07:54:53 -0700497 VideoCodecVP8 VP8;
498 VideoCodecVP9 VP9;
499 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25 +0000500};
501
phoglund@webrtc.org8bfee842012-02-17 09:32:48 +0000502// Simulcast is when the same stream is encoded multiple times with different
503// settings such as resolution.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000504struct SimulcastStream {
solenberg634b86e2016-09-01 07:54:53 -0700505 unsigned short width;
506 unsigned short height;
507 unsigned char numberOfTemporalLayers;
508 unsigned int maxBitrate; // kilobits/sec.
509 unsigned int targetBitrate; // kilobits/sec.
510 unsigned int minBitrate; // kilobits/sec.
511 unsigned int qpMax; // minimum quality
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000512};
513
sprangce4aef12015-11-02 07:23:20 -0800514struct SpatialLayer {
515 int scaling_factor_num;
516 int scaling_factor_den;
517 int target_bitrate_bps;
518 // TODO(ivica): Add max_quantizer and min_quantizer?
519};
520
solenberg634b86e2016-09-01 07:54:53 -0700521enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000522
niklase@google.com470e71d2011-07-07 08:21:25 +0000523// Common video codec properties
hta257dc392016-10-25 09:05:06 -0700524class VideoCodec {
525 public:
526 VideoCodec();
527
528 // Public variables. TODO(hta): Make them private with accessors.
solenberg634b86e2016-09-01 07:54:53 -0700529 VideoCodecType codecType;
530 char plName[kPayloadNameSize];
531 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000532
solenberg634b86e2016-09-01 07:54:53 -0700533 unsigned short width;
534 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25 +0000535
solenberg634b86e2016-09-01 07:54:53 -0700536 unsigned int startBitrate; // kilobits/sec.
537 unsigned int maxBitrate; // kilobits/sec.
538 unsigned int minBitrate; // kilobits/sec.
539 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52 +0000540
Stefan Holmer144475b2017-03-10 15:08:26 +0100541 uint32_t maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000542
solenberg634b86e2016-09-01 07:54:53 -0700543 unsigned int qpMax;
544 unsigned char numberOfSimulcastStreams;
545 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 07:23:20 -0800546 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000547
solenberg634b86e2016-09-01 07:54:53 -0700548 VideoCodecMode mode;
549 bool expect_encode_from_texture;
andresp@webrtc.org185bae42013-05-14 08:02:25 +0000550
ilnik04f4d122017-06-19 07:18:55 -0700551 // Timing frames configuration. There is delay of delay_ms between two
552 // consequent timing frames, excluding outliers. Frame is always made a
553 // timing frame if it's at least outlier_ratio in percent of "ideal" average
554 // frame given bitrate and framerate, i.e. if it's bigger than
555 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
556 // frames will not be sent too often usually. Yet large frames will always
557 // have timing information for debug purposes because they are more likely to
558 // cause extra delays.
559 struct TimingFrameTriggerThresholds {
560 int64_t delay_ms;
561 uint16_t outlier_ratio_percent;
562 } timing_frame_thresholds;
563
Peter Boström7b971e72016-01-19 16:26:16 +0100564 bool operator==(const VideoCodec& other) const = delete;
565 bool operator!=(const VideoCodec& other) const = delete;
hta257dc392016-10-25 09:05:06 -0700566
567 // Accessors for codec specific information.
568 // There is a const version of each that returns a reference,
569 // and a non-const version that returns a pointer, in order
570 // to allow modification of the parameters.
571 VideoCodecVP8* VP8();
572 const VideoCodecVP8& VP8() const;
573 VideoCodecVP9* VP9();
574 const VideoCodecVP9& VP9() const;
575 VideoCodecH264* H264();
576 const VideoCodecH264& H264() const;
577
hta527d3472016-11-16 23:23:04 -0800578 private:
hta257dc392016-10-25 09:05:06 -0700579 // TODO(hta): Consider replacing the union with a pointer type.
580 // This will allow removing the VideoCodec* types from this file.
hta527d3472016-11-16 23:23:04 -0800581 VideoCodecUnion codec_specific_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000582};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000583
Erik Språng08127a92016-11-16 16:41:30 +0100584class BitrateAllocation {
585 public:
586 static const uint32_t kMaxBitrateBps;
587 BitrateAllocation();
588
589 bool SetBitrate(size_t spatial_index,
590 size_t temporal_index,
591 uint32_t bitrate_bps);
592
erikvarga@webrtc.org01f2ec32017-11-15 14:58:23 +0100593 bool HasBitrate(size_t spatial_index, size_t temporal_index) const;
594
Erik Språng08127a92016-11-16 16:41:30 +0100595 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
596
erikvarga@webrtc.org01f2ec32017-11-15 14:58:23 +0100597 // Whether the specific spatial layers has the bitrate set in any of its
598 // temporal layers.
599 bool IsSpatialLayerUsed(size_t spatial_index) const;
600
Erik Språng08127a92016-11-16 16:41:30 +0100601 // Get the sum of all the temporal layer for a specific spatial layer.
602 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
603
604 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
605 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
606
607 inline bool operator==(const BitrateAllocation& other) const {
608 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
609 }
610 inline bool operator!=(const BitrateAllocation& other) const {
611 return !(*this == other);
612 }
613
sprangd0fc37a2017-06-22 05:40:25 -0700614 // Expensive, please use only in tests.
615 std::string ToString() const;
616 std::ostream& operator<<(std::ostream& os) const;
617
Erik Språng08127a92016-11-16 16:41:30 +0100618 private:
619 uint32_t sum_;
620 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
erikvarga@webrtc.org01f2ec32017-11-15 14:58:23 +0100621 bool has_bitrate_[kMaxSpatialLayers][kMaxTemporalStreams];
Erik Språng08127a92016-11-16 16:41:30 +0100622};
623
stefan64c0a0a2015-11-27 01:02:31 -0800624// Bandwidth over-use detector options. These are used to drive
625// experimentation with bandwidth estimation parameters.
626// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 10:43:01 -0800627// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
628// default constructed state. Can we move the relevant variables into that
629// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 01:02:31 -0800630struct OverUseDetectorOptions {
631 OverUseDetectorOptions()
solenberg634b86e2016-09-01 07:54:53 -0700632 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 01:02:31 -0800633 initial_offset(0),
634 initial_e(),
635 initial_process_noise(),
636 initial_avg_noise(0.0),
637 initial_var_noise(50) {
638 initial_e[0][0] = 100;
639 initial_e[1][1] = 1e-1;
640 initial_e[0][1] = initial_e[1][0] = 0;
641 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 05:13:21 -0800642 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 01:02:31 -0800643 }
644 double initial_slope;
645 double initial_offset;
646 double initial_e[2][2];
647 double initial_process_noise[2];
648 double initial_avg_noise;
649 double initial_var_noise;
650};
651
wu@webrtc.orga9890802013-12-13 00:21:03 +0000652// This structure will have the information about when packet is actually
653// received by socket.
654struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000655 PacketTime() : timestamp(-1), not_before(-1) {}
656 PacketTime(int64_t timestamp, int64_t not_before)
solenberg634b86e2016-09-01 07:54:53 -0700657 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orga9890802013-12-13 00:21:03 +0000658
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000659 int64_t timestamp; // Receive time after socket delivers the data.
660 int64_t not_before; // Earliest possible time the data could have arrived,
661 // indicating the potential error in the |timestamp|
662 // value,in case the system is busy.
663 // For example, the time of the last select() call.
664 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000665};
666
isheriff6b4b5f32016-06-08 00:24:21 -0700667// Minimum and maximum playout delay values from capture to render.
668// These are best effort values.
669//
670// A value < 0 indicates no change from previous valid value.
671//
672// min = max = 0 indicates that the receiver should try and render
673// frame as soon as possible.
674//
675// min = x, max = y indicates that the receiver is free to adapt
676// in the range (x, y) based on network jitter.
677//
678// Note: Given that this gets embedded in a union, it is up-to the owner to
679// initialize these values.
680struct PlayoutDelay {
681 int min_ms;
682 int max_ms;
683};
684
niklase@google.com470e71d2011-07-07 08:21:25 +0000685} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000686
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200687#endif // COMMON_TYPES_H_