blob: 7b62dbca09bf63fc2e301f92e967ce62ce2ad488 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
phoglund@webrtc.org8bfee842012-02-17 09:32:482 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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
andrew@webrtc.orgeda189b2013-09-09 17:50:1011#ifndef WEBRTC_COMMON_TYPES_H_
12#define WEBRTC_COMMON_TYPES_H_
niklase@google.com470e71d2011-07-07 08:21:2513
pbos@webrtc.orgf577ae92014-03-19 08:43:5714#include <stddef.h>
mallinath@webrtc.org0209e562014-03-21 00:41:2815#include <string.h>
pbos@webrtc.org1e92b0a2014-05-15 09:35:0616
kwiberg5bf4e082016-12-19 14:04:0417#include <ostream>
pbos@webrtc.org1e92b0a2014-05-15 09:35:0618#include <string>
pbos@webrtc.orgf577ae92014-03-19 08:43:5719#include <vector>
20
ilnik00d802b2017-04-11 17:34:3121#include "webrtc/api/video/video_content_type.h"
nisseaf916892017-01-10 15:44:2622#include "webrtc/api/video/video_rotation.h"
ilnik04f4d122017-06-19 14:18:5523#include "webrtc/api/video/video_timing.h"
Henrik Kjellandera80c16a2017-07-01 14:48:1524#include "webrtc/base/array_view.h"
25#include "webrtc/base/checks.h"
26#include "webrtc/base/optional.h"
andrew@webrtc.orgeda189b2013-09-09 17:50:1027#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:2528
andrew@webrtc.org88b8b0d2012-08-14 00:05:5629#if defined(_MSC_VER)
30// Disable "new behavior: elements of array will be default initialized"
31// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 14:54:5332#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5633#endif
34
kwiberg77eab702016-09-29 00:42:0135#if defined(WEBRTC_EXPORT)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5636#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg77eab702016-09-29 00:42:0137#elif defined(WEBRTC_DLL)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5638#define WEBRTC_DLLEXPORT _declspec(dllimport)
niklase@google.com470e71d2011-07-07 08:21:2539#else
andrew@webrtc.org88b8b0d2012-08-14 00:05:5640#define WEBRTC_DLLEXPORT
niklase@google.com470e71d2011-07-07 08:21:2541#endif
42
43#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:5644#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:2545#endif
46
Peter Boström8b79b072016-02-26 15:31:3747#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:4248
mallinath@webrtc.org0209e562014-03-21 00:41:2849#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:1050// Compares two strings without regard to case.
51#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
52// Compares characters of two strings without regard to case.
53#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
54#else
55#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
56#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
57#endif
58
niklase@google.com470e71d2011-07-07 08:21:2559namespace webrtc {
60
tommia6219cc2016-06-15 17:30:1461class RewindableStream {
62 public:
63 virtual ~RewindableStream() {}
64 virtual int Rewind() = 0;
niklase@google.com470e71d2011-07-07 08:21:2565};
66
tommia6219cc2016-06-15 17:30:1467class InStream : public RewindableStream {
68 public:
69 // Reads |len| bytes from file to |buf|. Returns the number of bytes read
70 // or -1 on error.
71 virtual int Read(void* buf, size_t len) = 0;
72};
73
74class OutStream : public RewindableStream {
75 public:
76 // Writes |len| bytes from |buf| to file. The actual writing may happen
77 // some time later. Call Flush() to force a write.
78 virtual bool Write(const void* buf, size_t len) = 0;
niklase@google.com470e71d2011-07-07 08:21:2579};
80
solenberg634b86e2016-09-01 14:54:5381enum TraceModule {
82 kTraceUndefined = 0,
83 // not a module, triggered from the engine code
84 kTraceVoice = 0x0001,
85 // not a module, triggered from the engine code
86 kTraceVideo = 0x0002,
87 // not a module, triggered from the utility code
88 kTraceUtility = 0x0003,
89 kTraceRtpRtcp = 0x0004,
90 kTraceTransport = 0x0005,
91 kTraceSrtp = 0x0006,
92 kTraceAudioCoding = 0x0007,
93 kTraceAudioMixerServer = 0x0008,
94 kTraceAudioMixerClient = 0x0009,
95 kTraceFile = 0x000a,
96 kTraceAudioProcessing = 0x000b,
97 kTraceVideoCoding = 0x0010,
98 kTraceVideoMixer = 0x0011,
99 kTraceAudioDevice = 0x0012,
100 kTraceVideoRenderer = 0x0014,
101 kTraceVideoCapture = 0x0015,
102 kTraceRemoteBitrateEstimator = 0x0017,
niklase@google.com470e71d2011-07-07 08:21:25103};
104
solenberg634b86e2016-09-01 14:54:53105enum TraceLevel {
106 kTraceNone = 0x0000, // no trace
107 kTraceStateInfo = 0x0001,
108 kTraceWarning = 0x0002,
109 kTraceError = 0x0004,
110 kTraceCritical = 0x0008,
111 kTraceApiCall = 0x0010,
112 kTraceDefault = 0x00ff,
niklase@google.com470e71d2011-07-07 08:21:25113
solenberg634b86e2016-09-01 14:54:53114 kTraceModuleCall = 0x0020,
115 kTraceMemory = 0x0100, // memory info
116 kTraceTimer = 0x0200, // timing info
117 kTraceStream = 0x0400, // "continuous" stream of data
niklase@google.com470e71d2011-07-07 08:21:25118
solenberg634b86e2016-09-01 14:54:53119 // used for debug purposes
120 kTraceDebug = 0x0800, // debug
121 kTraceInfo = 0x1000, // debug info
niklase@google.com470e71d2011-07-07 08:21:25122
solenberg634b86e2016-09-01 14:54:53123 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
124 kTraceTerseInfo = 0x2000,
andrew@webrtc.org655d8f52012-11-20 07:34:45125
solenberg634b86e2016-09-01 14:54:53126 kTraceAll = 0xffff
niklase@google.com470e71d2011-07-07 08:21:25127};
128
129// External Trace API
andrew@webrtc.org23ec30b2012-11-15 05:33:25130class TraceCallback {
131 public:
132 virtual void Print(TraceLevel level, const char* message, int length) = 0;
niklase@google.com470e71d2011-07-07 08:21:25133
andrew@webrtc.org23ec30b2012-11-15 05:33:25134 protected:
135 virtual ~TraceCallback() {}
136 TraceCallback() {}
137};
niklase@google.com470e71d2011-07-07 08:21:25138
solenberg634b86e2016-09-01 14:54:53139enum FileFormats {
140 kFileFormatWavFile = 1,
141 kFileFormatCompressedFile = 2,
142 kFileFormatPreencodedFile = 4,
143 kFileFormatPcm16kHzFile = 7,
144 kFileFormatPcm8kHzFile = 8,
lliuubc436ed2017-03-31 23:32:28145 kFileFormatPcm32kHzFile = 9
niklase@google.com470e71d2011-07-07 08:21:25146};
147
pbos22993e12015-10-19 09:39:06148enum FrameType {
149 kEmptyFrame = 0,
150 kAudioFrameSpeech = 1,
151 kAudioFrameCN = 2,
152 kVideoFrameKey = 3,
153 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27154};
155
sprang@webrtc.orgdc50aae2013-11-20 16:47:07156// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07157struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07158 RtcpStatistics()
solenberg634b86e2016-09-01 14:54:53159 : fraction_lost(0),
160 cumulative_lost(0),
161 extended_max_sequence_number(0),
162 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07163
164 uint8_t fraction_lost;
165 uint32_t cumulative_lost;
166 uint32_t extended_max_sequence_number;
167 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07168};
169
sprang@webrtc.orgdc50aae2013-11-20 16:47:07170class RtcpStatisticsCallback {
171 public:
172 virtual ~RtcpStatisticsCallback() {}
173
174 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
175 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16176 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07177};
178
asapersson@webrtc.org8098e072014-02-19 11:59:02179// Statistics for RTCP packet types.
180struct RtcpPacketTypeCounter {
181 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 14:54:53182 : first_packet_time_ms(-1),
183 nack_packets(0),
184 fir_packets(0),
185 pli_packets(0),
186 nack_requests(0),
187 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02188
189 void Add(const RtcpPacketTypeCounter& other) {
190 nack_packets += other.nack_packets;
191 fir_packets += other.fir_packets;
192 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30193 nack_requests += other.nack_requests;
194 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11195 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 14:54:53196 (other.first_packet_time_ms < first_packet_time_ms ||
197 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11198 // Use oldest time.
199 first_packet_time_ms = other.first_packet_time_ms;
200 }
201 }
202
sprang07fb9be2016-02-24 15:55:00203 void Subtract(const RtcpPacketTypeCounter& other) {
204 nack_packets -= other.nack_packets;
205 fir_packets -= other.fir_packets;
206 pli_packets -= other.pli_packets;
207 nack_requests -= other.nack_requests;
208 unique_nack_requests -= other.unique_nack_requests;
209 if (other.first_packet_time_ms != -1 &&
210 (other.first_packet_time_ms > first_packet_time_ms ||
211 first_packet_time_ms == -1)) {
212 // Use youngest time.
213 first_packet_time_ms = other.first_packet_time_ms;
214 }
215 }
216
asapersson@webrtc.orgd08d3892014-12-16 12:03:11217 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
218 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02219 }
220
asapersson@webrtc.org2dd31342014-10-29 12:42:30221 int UniqueNackRequestsInPercent() const {
222 if (nack_requests == 0) {
223 return 0;
224 }
solenberg634b86e2016-09-01 14:54:53225 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
226 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30227 }
228
solenberg634b86e2016-09-01 14:54:53229 int64_t first_packet_time_ms; // Time when first packet is sent/received.
230 uint32_t nack_packets; // Number of RTCP NACK packets.
231 uint32_t fir_packets; // Number of RTCP FIR packets.
232 uint32_t pli_packets; // Number of RTCP PLI packets.
233 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30234 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02235};
236
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00237class RtcpPacketTypeCounterObserver {
238 public:
239 virtual ~RtcpPacketTypeCounterObserver() {}
240 virtual void RtcpPacketTypesCounterUpdated(
241 uint32_t ssrc,
242 const RtcpPacketTypeCounter& packet_counter) = 0;
243};
244
asapersson@webrtc.orgd08d3892014-12-16 12:03:11245// Rate statistics for a stream.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07246struct BitrateStatistics {
sprangcd349d92016-07-13 16:11:28247 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.orgdc50aae2013-11-20 16:47:07248
solenberg634b86e2016-09-01 14:54:53249 uint32_t bitrate_bps; // Bitrate in bits per second.
250 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07251};
252
253// Callback, used to notify an observer whenever new rates have been estimated.
254class BitrateStatisticsObserver {
255 public:
256 virtual ~BitrateStatisticsObserver() {}
257
sprangcd349d92016-07-13 16:11:28258 virtual void Notify(uint32_t total_bitrate_bps,
259 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29260 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07261};
262
pbos@webrtc.orgce4e9a32014-12-18 13:50:16263struct FrameCounts {
264 FrameCounts() : key_frames(0), delta_frames(0) {}
265 int key_frames;
266 int delta_frames;
267};
268
asapersson@webrtc.orgd08d3892014-12-16 12:03:11269// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07270class FrameCountObserver {
271 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54272 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16273 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
274 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07275};
276
stefan@webrtc.org168f23f2014-07-11 13:44:02277// Callback, used to notify an observer whenever the send-side delay is updated.
278class SendSideDelayObserver {
279 public:
280 virtual ~SendSideDelayObserver() {}
281 virtual void SendSideDelayUpdated(int avg_delay_ms,
282 int max_delay_ms,
283 uint32_t ssrc) = 0;
284};
285
asapersson35151f32016-05-03 06:44:01286// Callback, used to notify an observer whenever a packet is sent to the
287// transport.
288// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
289// Remove SendSideDelayObserver once possible.
290class SendPacketObserver {
291 public:
292 virtual ~SendPacketObserver() {}
293 virtual void OnSendPacket(uint16_t packet_id,
294 int64_t capture_time_ms,
295 uint32_t ssrc) = 0;
296};
297
michaelt4da30442016-11-17 09:38:43298// Callback, used to notify an observer when the overhead per packet
299// has changed.
300class OverheadObserver {
301 public:
302 virtual ~OverheadObserver() = default;
303 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
304};
305
niklase@google.com470e71d2011-07-07 08:21:25306// ==================================================================
307// Voice specific types
308// ==================================================================
309
310// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28311struct CodecInst {
312 int pltype;
313 char plname[RTP_PAYLOAD_NAME_SIZE];
314 int plfreq;
315 int pacsize;
Peter Kasting69558702016-01-13 00:26:35316 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28317 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
318
319 bool operator==(const CodecInst& other) const {
320 return pltype == other.pltype &&
321 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenberg634b86e2016-09-01 14:54:53322 plfreq == other.plfreq && pacsize == other.pacsize &&
323 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28324 }
325
solenberg634b86e2016-09-01 14:54:53326 bool operator!=(const CodecInst& other) const { return !(*this == other); }
kwiberg5bf4e082016-12-19 14:04:04327
328 friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
329 os << "{pltype: " << ci.pltype;
330 os << ", plname: " << ci.plname;
331 os << ", plfreq: " << ci.plfreq;
332 os << ", pacsize: " << ci.pacsize;
333 os << ", channels: " << ci.channels;
334 os << ", rate: " << ci.rate << "}";
335 return os;
336 }
niklase@google.com470e71d2011-07-07 08:21:25337};
338
niklase@google.com470e71d2011-07-07 08:21:25339// RTP
solenberg634b86e2016-09-01 14:54:53340enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25341
solenberg634b86e2016-09-01 14:54:53342enum PayloadFrequencies {
343 kFreq8000Hz = 8000,
344 kFreq16000Hz = 16000,
345 kFreq32000Hz = 32000
niklase@google.com470e71d2011-07-07 08:21:25346};
347
solenberg634b86e2016-09-01 14:54:53348// Degree of bandwidth reduction.
349enum VadModes {
350 kVadConventional = 0, // lowest reduction
351 kVadAggressiveLow,
352 kVadAggressiveMid,
353 kVadAggressiveHigh // highest reduction
niklase@google.com470e71d2011-07-07 08:21:25354};
355
solenberg634b86e2016-09-01 14:54:53356// NETEQ statistics.
357struct NetworkStatistics {
358 // current jitter buffer size in ms
359 uint16_t currentBufferSize;
360 // preferred (optimal) buffer size in ms
361 uint16_t preferredBufferSize;
362 // adding extra delay due to "peaky jitter"
363 bool jitterPeaksFound;
364 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
365 uint16_t currentPacketLossRate;
366 // Late loss rate; fraction between 0 and 1, scaled to Q14.
367 uint16_t currentDiscardRate;
368 // fraction (of original stream) of synthesized audio inserted through
369 // expansion (in Q14)
370 uint16_t currentExpandRate;
371 // fraction (of original stream) of synthesized speech inserted through
372 // expansion (in Q14)
373 uint16_t currentSpeechExpandRate;
374 // fraction of synthesized speech inserted through pre-emptive expansion
375 // (in Q14)
376 uint16_t currentPreemptiveRate;
377 // fraction of data removed through acceleration (in Q14)
378 uint16_t currentAccelerateRate;
379 // fraction of data coming from secondary decoding (in Q14)
380 uint16_t currentSecondaryDecodedRate;
381 // clock-drift in parts-per-million (negative or positive)
382 int32_t clockDriftPPM;
383 // average packet waiting time in the jitter buffer (ms)
384 int meanWaitingTimeMs;
385 // median packet waiting time in the jitter buffer (ms)
386 int medianWaitingTimeMs;
387 // min packet waiting time in the jitter buffer (ms)
388 int minWaitingTimeMs;
389 // max packet waiting time in the jitter buffer (ms)
390 int maxWaitingTimeMs;
391 // added samples in off mode due to packet loss
392 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25393};
394
wu@webrtc.org24301a62013-12-13 19:17:43395// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
396struct AudioDecodingCallStats {
397 AudioDecodingCallStats()
398 : calls_to_silence_generator(0),
399 calls_to_neteq(0),
400 decoded_normal(0),
401 decoded_plc(0),
402 decoded_cng(0),
henrik.lundin63489782016-09-20 08:47:12403 decoded_plc_cng(0),
404 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43405
406 int calls_to_silence_generator; // Number of calls where silence generated,
407 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 14:54:53408 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43409 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 14:54:53410 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43411 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
412 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 08:47:12413 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43414};
415
niklase@google.com470e71d2011-07-07 08:21:25416// ==================================================================
417// Video specific types
418// ==================================================================
419
nisseeb44b392017-04-28 14:18:05420// TODO(nisse): Delete, and switch to fourcc values everywhere?
421// Supported video types.
422enum class VideoType {
423 kUnknown,
424 kI420,
425 kIYUV,
426 kRGB24,
427 kABGR,
428 kARGB,
429 kARGB4444,
430 kRGB565,
431 kARGB1555,
432 kYUY2,
433 kYV12,
434 kUYVY,
435 kMJPEG,
436 kNV21,
437 kNV12,
438 kBGRA,
niklase@google.com470e71d2011-07-07 08:21:25439};
440
441// Video codec
solenberg634b86e2016-09-01 14:54:53442enum { kPayloadNameSize = 32 };
443enum { kMaxSimulcastStreams = 4 };
sprangce4aef12015-11-02 15:23:20444enum { kMaxSpatialLayers = 5 };
solenberg634b86e2016-09-01 14:54:53445enum { kMaxTemporalStreams = 4 };
niklase@google.com470e71d2011-07-07 08:21:25446
solenberg634b86e2016-09-01 14:54:53447enum VideoCodecComplexity {
448 kComplexityNormal = 0,
449 kComplexityHigh = 1,
450 kComplexityHigher = 2,
451 kComplexityMax = 3
niklase@google.com470e71d2011-07-07 08:21:25452};
453
stefan@webrtc.orgefd0a482011-12-29 10:12:35454enum VP8ResilienceMode {
455 kResilienceOff, // The stream produced by the encoder requires a
456 // recovery frame (typically a key frame) to be
457 // decodable after a packet loss.
458 kResilientStream, // A stream produced by the encoder is resilient to
459 // packet losses, but packets within a frame subsequent
460 // to a loss can't be decoded.
461 kResilientFrames // Same as kResilientStream but with added resilience
462 // within a frame.
463};
464
Peter Boström7b971e72016-01-19 15:26:16465class TemporalLayersFactory;
niklase@google.com470e71d2011-07-07 08:21:25466// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28467struct VideoCodecVP8 {
nisse3257b162017-03-21 08:54:13468 // TODO(nisse): Unused, delete?
solenberg634b86e2016-09-01 14:54:53469 bool pictureLossIndicationOn;
mallinath@webrtc.org0209e562014-03-21 00:41:28470 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 14:54:53471 VP8ResilienceMode resilience;
472 unsigned char numberOfTemporalLayers;
473 bool denoisingOn;
474 bool errorConcealmentOn;
475 bool automaticResizeOn;
476 bool frameDroppingOn;
477 int keyFrameInterval;
Erik Språng08127a92016-11-16 15:41:30478 TemporalLayersFactory* tl_factory;
niklase@google.com470e71d2011-07-07 08:21:25479};
480
asaperssona9455ab2015-07-31 13:10:09481// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48482struct VideoCodecVP9 {
483 VideoCodecComplexity complexity;
asapersson15dcb382017-06-08 09:55:08484 bool resilienceOn;
solenberg634b86e2016-09-01 14:54:53485 unsigned char numberOfTemporalLayers;
486 bool denoisingOn;
487 bool frameDroppingOn;
488 int keyFrameInterval;
489 bool adaptiveQpMode;
490 bool automaticResizeOn;
491 unsigned char numberOfSpatialLayers;
492 bool flexibleMode;
marpan@webrtc.org5b883172014-11-01 06:10:48493};
494
magjede69a1a92016-11-25 18:06:31495// TODO(magjed): Move this and other H264 related classes out to their own file.
496namespace H264 {
497
498enum Profile {
499 kProfileConstrainedBaseline,
500 kProfileBaseline,
501 kProfileMain,
502 kProfileConstrainedHigh,
503 kProfileHigh,
504};
505
506} // namespace H264
507
stefan@webrtc.orgb9f54532014-07-04 12:42:07508// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48509struct VideoCodecH264 {
solenberg634b86e2016-09-01 14:54:53510 bool frameDroppingOn;
511 int keyFrameInterval;
marpan@webrtc.org5b883172014-11-01 06:10:48512 // These are NULL/0 if not externally negotiated.
513 const uint8_t* spsData;
solenberg634b86e2016-09-01 14:54:53514 size_t spsLen;
marpan@webrtc.org5b883172014-11-01 06:10:48515 const uint8_t* ppsData;
solenberg634b86e2016-09-01 14:54:53516 size_t ppsLen;
magjede69a1a92016-11-25 18:06:31517 H264::Profile profile;
stefan@webrtc.orgb9f54532014-07-04 12:42:07518};
519
niklase@google.com470e71d2011-07-07 08:21:25520// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48521enum VideoCodecType {
522 kVideoCodecVP8,
523 kVideoCodecVP9,
524 kVideoCodecH264,
525 kVideoCodecI420,
526 kVideoCodecRED,
527 kVideoCodecULPFEC,
brandtr87d7d772016-11-07 11:03:41528 kVideoCodecFlexfec,
marpan@webrtc.org5b883172014-11-01 06:10:48529 kVideoCodecGeneric,
530 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25531};
532
Erik Språng08127a92016-11-16 15:41:30533// Translates from name of codec to codec type and vice versa.
magjed10165ab2016-11-22 18:16:57534rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type);
Erik Språng08127a92016-11-16 15:41:30535rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name);
536
marpan@webrtc.org5b883172014-11-01 06:10:48537union VideoCodecUnion {
solenberg634b86e2016-09-01 14:54:53538 VideoCodecVP8 VP8;
539 VideoCodecVP9 VP9;
540 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25541};
542
phoglund@webrtc.org8bfee842012-02-17 09:32:48543// Simulcast is when the same stream is encoded multiple times with different
544// settings such as resolution.
mallinath@webrtc.org0209e562014-03-21 00:41:28545struct SimulcastStream {
solenberg634b86e2016-09-01 14:54:53546 unsigned short width;
547 unsigned short height;
548 unsigned char numberOfTemporalLayers;
549 unsigned int maxBitrate; // kilobits/sec.
550 unsigned int targetBitrate; // kilobits/sec.
551 unsigned int minBitrate; // kilobits/sec.
552 unsigned int qpMax; // minimum quality
pwestin@webrtc.org1da1ce02011-10-13 15:19:55553};
554
sprangce4aef12015-11-02 15:23:20555struct SpatialLayer {
556 int scaling_factor_num;
557 int scaling_factor_den;
558 int target_bitrate_bps;
559 // TODO(ivica): Add max_quantizer and min_quantizer?
560};
561
solenberg634b86e2016-09-01 14:54:53562enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgeb917922013-02-18 14:40:18563
niklase@google.com470e71d2011-07-07 08:21:25564// Common video codec properties
hta257dc392016-10-25 16:05:06565class VideoCodec {
566 public:
567 VideoCodec();
568
569 // Public variables. TODO(hta): Make them private with accessors.
solenberg634b86e2016-09-01 14:54:53570 VideoCodecType codecType;
571 char plName[kPayloadNameSize];
572 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25573
solenberg634b86e2016-09-01 14:54:53574 unsigned short width;
575 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25576
solenberg634b86e2016-09-01 14:54:53577 unsigned int startBitrate; // kilobits/sec.
578 unsigned int maxBitrate; // kilobits/sec.
579 unsigned int minBitrate; // kilobits/sec.
580 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52581
Stefan Holmer144475b2017-03-10 14:08:26582 uint32_t maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25583
solenberg634b86e2016-09-01 14:54:53584 unsigned int qpMax;
585 unsigned char numberOfSimulcastStreams;
586 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 15:23:20587 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18588
solenberg634b86e2016-09-01 14:54:53589 VideoCodecMode mode;
590 bool expect_encode_from_texture;
andresp@webrtc.org185bae42013-05-14 08:02:25591
ilnik04f4d122017-06-19 14:18:55592 // Timing frames configuration. There is delay of delay_ms between two
593 // consequent timing frames, excluding outliers. Frame is always made a
594 // timing frame if it's at least outlier_ratio in percent of "ideal" average
595 // frame given bitrate and framerate, i.e. if it's bigger than
596 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
597 // frames will not be sent too often usually. Yet large frames will always
598 // have timing information for debug purposes because they are more likely to
599 // cause extra delays.
600 struct TimingFrameTriggerThresholds {
601 int64_t delay_ms;
602 uint16_t outlier_ratio_percent;
603 } timing_frame_thresholds;
604
Peter Boström7b971e72016-01-19 15:26:16605 bool operator==(const VideoCodec& other) const = delete;
606 bool operator!=(const VideoCodec& other) const = delete;
hta257dc392016-10-25 16:05:06607
608 // Accessors for codec specific information.
609 // There is a const version of each that returns a reference,
610 // and a non-const version that returns a pointer, in order
611 // to allow modification of the parameters.
612 VideoCodecVP8* VP8();
613 const VideoCodecVP8& VP8() const;
614 VideoCodecVP9* VP9();
615 const VideoCodecVP9& VP9() const;
616 VideoCodecH264* H264();
617 const VideoCodecH264& H264() const;
618
hta527d3472016-11-17 07:23:04619 private:
hta257dc392016-10-25 16:05:06620 // TODO(hta): Consider replacing the union with a pointer type.
621 // This will allow removing the VideoCodec* types from this file.
hta527d3472016-11-17 07:23:04622 VideoCodecUnion codec_specific_;
niklase@google.com470e71d2011-07-07 08:21:25623};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04624
Erik Språng08127a92016-11-16 15:41:30625class BitrateAllocation {
626 public:
627 static const uint32_t kMaxBitrateBps;
628 BitrateAllocation();
629
630 bool SetBitrate(size_t spatial_index,
631 size_t temporal_index,
632 uint32_t bitrate_bps);
633
634 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
635
636 // Get the sum of all the temporal layer for a specific spatial layer.
637 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
638
639 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
640 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
641
642 inline bool operator==(const BitrateAllocation& other) const {
643 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
644 }
645 inline bool operator!=(const BitrateAllocation& other) const {
646 return !(*this == other);
647 }
648
sprangd0fc37a2017-06-22 12:40:25649 // Expensive, please use only in tests.
650 std::string ToString() const;
651 std::ostream& operator<<(std::ostream& os) const;
652
Erik Språng08127a92016-11-16 15:41:30653 private:
654 uint32_t sum_;
655 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
656};
657
stefan64c0a0a2015-11-27 09:02:31658// Bandwidth over-use detector options. These are used to drive
659// experimentation with bandwidth estimation parameters.
660// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 18:43:01661// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
662// default constructed state. Can we move the relevant variables into that
663// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 09:02:31664struct OverUseDetectorOptions {
665 OverUseDetectorOptions()
solenberg634b86e2016-09-01 14:54:53666 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 09:02:31667 initial_offset(0),
668 initial_e(),
669 initial_process_noise(),
670 initial_avg_noise(0.0),
671 initial_var_noise(50) {
672 initial_e[0][0] = 100;
673 initial_e[1][1] = 1e-1;
674 initial_e[0][1] = initial_e[1][0] = 0;
675 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 13:13:21676 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 09:02:31677 }
678 double initial_slope;
679 double initial_offset;
680 double initial_e[2][2];
681 double initial_process_noise[2];
682 double initial_avg_noise;
683 double initial_var_noise;
684};
685
wu@webrtc.orga9890802013-12-13 00:21:03686// This structure will have the information about when packet is actually
687// received by socket.
688struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47689 PacketTime() : timestamp(-1), not_before(-1) {}
690 PacketTime(int64_t timestamp, int64_t not_before)
solenberg634b86e2016-09-01 14:54:53691 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orga9890802013-12-13 00:21:03692
henrike@webrtc.org82d3cb62014-04-29 17:50:47693 int64_t timestamp; // Receive time after socket delivers the data.
694 int64_t not_before; // Earliest possible time the data could have arrived,
695 // indicating the potential error in the |timestamp|
696 // value,in case the system is busy.
697 // For example, the time of the last select() call.
698 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03699};
700
isheriff6b4b5f32016-06-08 07:24:21701// Minimum and maximum playout delay values from capture to render.
702// These are best effort values.
703//
704// A value < 0 indicates no change from previous valid value.
705//
706// min = max = 0 indicates that the receiver should try and render
707// frame as soon as possible.
708//
709// min = x, max = y indicates that the receiver is free to adapt
710// in the range (x, y) based on network jitter.
711//
712// Note: Given that this gets embedded in a union, it is up-to the owner to
713// initialize these values.
714struct PlayoutDelay {
715 int min_ms;
716 int max_ms;
717};
718
danilchapef8d7732017-04-19 09:59:48719// Class to represent RtpStreamId which is a string.
720// Unlike std::string, it can be copied with memcpy and cleared with memset.
721// Empty value represent unset RtpStreamId.
722class StreamId {
723 public:
724 // Stream id is limited to 16 bytes because it is the maximum length
725 // that can be encoded with one-byte header extensions.
726 static constexpr size_t kMaxSize = 16;
727
eladalond0244c22017-06-08 11:19:13728 static bool IsLegalName(rtc::ArrayView<const char> name);
729
danilchapef8d7732017-04-19 09:59:48730 StreamId() { value_[0] = 0; }
731 explicit StreamId(rtc::ArrayView<const char> value) {
732 Set(value.data(), value.size());
733 }
734 StreamId(const StreamId&) = default;
735 StreamId& operator=(const StreamId&) = default;
736
737 bool empty() const { return value_[0] == 0; }
738 const char* data() const { return value_; }
739 size_t size() const { return strnlen(value_, kMaxSize); }
740
741 void Set(rtc::ArrayView<const uint8_t> value) {
742 Set(reinterpret_cast<const char*>(value.data()), value.size());
743 }
744 void Set(const char* data, size_t size);
745
746 friend bool operator==(const StreamId& lhs, const StreamId& rhs) {
747 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
748 }
749 friend bool operator!=(const StreamId& lhs, const StreamId& rhs) {
750 return !(lhs == rhs);
751 }
752
753 private:
754 char value_[kMaxSize];
755};
756
solenberg@webrtc.orgb1f50102014-03-24 10:38:25757struct RTPHeaderExtension {
sprang@webrtc.org30933902015-03-17 14:33:12758 RTPHeaderExtension();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25759
760 bool hasTransmissionTimeOffset;
761 int32_t transmissionTimeOffset;
762 bool hasAbsoluteSendTime;
763 uint32_t absoluteSendTime;
sprang@webrtc.org30933902015-03-17 14:33:12764 bool hasTransportSequenceNumber;
765 uint16_t transportSequenceNumber;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25766
767 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
768 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
769 bool hasAudioLevel;
Minyue4cee4192015-08-10 13:08:36770 bool voiceActivity;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25771 uint8_t audioLevel;
guoweis@webrtc.org45362892015-03-04 22:55:15772
773 // For Coordination of Video Orientation. See
774 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
775 // ts_126114v120700p.pdf
776 bool hasVideoRotation;
magjed71eb61c2016-09-08 10:24:58777 VideoRotation videoRotation;
isheriff6b4b5f32016-06-08 07:24:21778
ilnik00d802b2017-04-11 17:34:31779 // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
780 // a corresponding bool flag.
781 bool hasVideoContentType;
782 VideoContentType videoContentType;
783
ilnik04f4d122017-06-19 14:18:55784 bool has_video_timing;
785 VideoTiming video_timing;
786
isheriff6b4b5f32016-06-08 07:24:21787 PlayoutDelay playout_delay = {-1, -1};
danilchapef8d7732017-04-19 09:59:48788
789 // For identification of a stream when ssrc is not signaled. See
790 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
791 // TODO(danilchap): Update url from draft to release version.
792 StreamId stream_id;
793 StreamId repaired_stream_id;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25794};
795
796struct RTPHeader {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22797 RTPHeader();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25798
799 bool markerBit;
800 uint8_t payloadType;
801 uint16_t sequenceNumber;
802 uint32_t timestamp;
803 uint32_t ssrc;
804 uint8_t numCSRCs;
805 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org4591fbd2014-11-20 22:28:14806 size_t paddingLength;
807 size_t headerLength;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25808 int payload_type_frequency;
809 RTPHeaderExtension extension;
810};
811
asapersson@webrtc.org44149392015-02-04 08:34:47812struct RtpPacketCounter {
813 RtpPacketCounter()
solenberg634b86e2016-09-01 14:54:53814 : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
asapersson@webrtc.org44149392015-02-04 08:34:47815
816 void Add(const RtpPacketCounter& other) {
817 header_bytes += other.header_bytes;
818 payload_bytes += other.payload_bytes;
819 padding_bytes += other.padding_bytes;
820 packets += other.packets;
821 }
822
Erik Språng22c2b482016-03-01 08:40:42823 void Subtract(const RtpPacketCounter& other) {
kwibergb890c95c2016-11-29 13:30:40824 RTC_DCHECK_GE(header_bytes, other.header_bytes);
Erik Språng22c2b482016-03-01 08:40:42825 header_bytes -= other.header_bytes;
kwibergb890c95c2016-11-29 13:30:40826 RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
Erik Språng22c2b482016-03-01 08:40:42827 payload_bytes -= other.payload_bytes;
kwibergb890c95c2016-11-29 13:30:40828 RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
Erik Språng22c2b482016-03-01 08:40:42829 padding_bytes -= other.padding_bytes;
kwibergb890c95c2016-11-29 13:30:40830 RTC_DCHECK_GE(packets, other.packets);
Erik Språng22c2b482016-03-01 08:40:42831 packets -= other.packets;
832 }
833
asapersson@webrtc.org44149392015-02-04 08:34:47834 void AddPacket(size_t packet_length, const RTPHeader& header) {
835 ++packets;
836 header_bytes += header.headerLength;
837 padding_bytes += header.paddingLength;
838 payload_bytes +=
839 packet_length - (header.headerLength + header.paddingLength);
840 }
841
842 size_t TotalBytes() const {
843 return header_bytes + payload_bytes + padding_bytes;
844 }
845
846 size_t header_bytes; // Number of bytes used by RTP headers.
847 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
848 size_t padding_bytes; // Number of padding bytes.
849 uint32_t packets; // Number of packets.
850};
851
852// Data usage statistics for a (rtp) stream.
853struct StreamDataCounters {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22854 StreamDataCounters();
asapersson@webrtc.org44149392015-02-04 08:34:47855
856 void Add(const StreamDataCounters& other) {
857 transmitted.Add(other.transmitted);
858 retransmitted.Add(other.retransmitted);
859 fec.Add(other.fec);
860 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 14:54:53861 (other.first_packet_time_ms < first_packet_time_ms ||
862 first_packet_time_ms == -1)) {
asapersson@webrtc.org44149392015-02-04 08:34:47863 // Use oldest time.
864 first_packet_time_ms = other.first_packet_time_ms;
865 }
866 }
867
Erik Språng22c2b482016-03-01 08:40:42868 void Subtract(const StreamDataCounters& other) {
869 transmitted.Subtract(other.transmitted);
870 retransmitted.Subtract(other.retransmitted);
871 fec.Subtract(other.fec);
872 if (other.first_packet_time_ms != -1 &&
873 (other.first_packet_time_ms > first_packet_time_ms ||
874 first_packet_time_ms == -1)) {
875 // Use youngest time.
876 first_packet_time_ms = other.first_packet_time_ms;
877 }
878 }
879
asapersson@webrtc.org44149392015-02-04 08:34:47880 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
881 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
882 }
883
884 // Returns the number of bytes corresponding to the actual media payload (i.e.
885 // RTP headers, padding, retransmissions and fec packets are excluded).
886 // Note this function does not have meaning for an RTX stream.
887 size_t MediaPayloadBytes() const {
888 return transmitted.payload_bytes - retransmitted.payload_bytes -
889 fec.payload_bytes;
890 }
891
solenberg634b86e2016-09-01 14:54:53892 int64_t first_packet_time_ms; // Time when first packet is sent/received.
893 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47894 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
solenberg634b86e2016-09-01 14:54:53895 RtpPacketCounter fec; // Number of redundancy packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47896};
897
898// Callback, called whenever byte/packet counts have been updated.
899class StreamDataCountersCallback {
900 public:
901 virtual ~StreamDataCountersCallback() {}
902
903 virtual void DataCountersUpdated(const StreamDataCounters& counters,
904 uint32_t ssrc) = 0;
905};
pbosda903ea2015-10-02 09:36:56906
907// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
908// RTCP mode is described by RFC 5506.
909enum class RtcpMode { kOff, kCompound, kReducedSize };
910
pbos1ba8d392016-05-02 03:18:34911enum NetworkState {
912 kNetworkUp,
913 kNetworkDown,
914};
915
niklase@google.com470e71d2011-07-07 08:21:25916} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10917
918#endif // WEBRTC_COMMON_TYPES_H_