blob: 06733be168d6a08e351d0b954a2e84b03a7e4991 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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.org5cf83f42013-09-09 17:50:1011#ifndef WEBRTC_COMMON_TYPES_H_
12#define WEBRTC_COMMON_TYPES_H_
andrew@webrtc.orgb015cbe2012-10-22 18:19:2313
pbos@webrtc.orge2a7a772014-03-19 08:43:5714#include <stddef.h>
mallinath@webrtc.org18c29452014-03-21 00:41:2815#include <string.h>
pbos@webrtc.org7e686932014-05-15 09:35:0616
kwiberg1c0ef6d2016-12-19 14:04:0417#include <ostream>
pbos@webrtc.org7e686932014-05-15 09:35:0618#include <string>
pbos@webrtc.orge2a7a772014-03-19 08:43:5719#include <vector>
20
ilnikcb436f62017-04-11 17:34:3121#include "webrtc/api/video/video_content_type.h"
nissef0daa062017-01-10 15:44:2622#include "webrtc/api/video/video_rotation.h"
danilchapb7801512017-04-19 09:59:4823#include "webrtc/base/array_view.h"
kwibergc1a5e1b2016-11-29 13:30:4024#include "webrtc/base/checks.h"
Erik Språngfafcfc02016-11-16 15:41:3025#include "webrtc/base/optional.h"
andrew@webrtc.org5cf83f42013-09-09 17:50:1026#include "webrtc/typedefs.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2327
28#if defined(_MSC_VER)
29// Disable "new behavior: elements of array will be default initialized"
30// warning. Affects OverUseDetectorOptions.
solenbergfaa58c62016-09-01 14:54:5331#pragma warning(disable : 4351)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2332#endif
33
kwiberg15b966d2016-09-29 00:42:0134#if defined(WEBRTC_EXPORT)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2335#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg15b966d2016-09-29 00:42:0136#elif defined(WEBRTC_DLL)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2337#define WEBRTC_DLLEXPORT _declspec(dllimport)
38#else
39#define WEBRTC_DLLEXPORT
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
Peter Boströmcd71dc62016-02-26 15:31:3746#define RTP_PAYLOAD_NAME_SIZE 32u
andrew@webrtc.orgb015cbe2012-10-22 18:19:2347
mallinath@webrtc.org18c29452014-03-21 00:41:2848#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.org5cf83f42013-09-09 17:50:1049// Compares two strings without regard to case.
50#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
51// Compares characters of two strings without regard to case.
52#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
53#else
54#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
55#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
56#endif
57
andrew@webrtc.orgb015cbe2012-10-22 18:19:2358namespace webrtc {
59
tommia6d985c2016-06-15 17:30:1460class RewindableStream {
61 public:
62 virtual ~RewindableStream() {}
63 virtual int Rewind() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2364};
65
tommia6d985c2016-06-15 17:30:1466class InStream : public RewindableStream {
67 public:
68 // Reads |len| bytes from file to |buf|. Returns the number of bytes read
69 // or -1 on error.
70 virtual int Read(void* buf, size_t len) = 0;
71};
72
73class OutStream : public RewindableStream {
74 public:
75 // Writes |len| bytes from |buf| to file. The actual writing may happen
76 // some time later. Call Flush() to force a write.
77 virtual bool Write(const void* buf, size_t len) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2378};
79
solenbergfaa58c62016-09-01 14:54:5380enum TraceModule {
81 kTraceUndefined = 0,
82 // not a module, triggered from the engine code
83 kTraceVoice = 0x0001,
84 // not a module, triggered from the engine code
85 kTraceVideo = 0x0002,
86 // not a module, triggered from the utility code
87 kTraceUtility = 0x0003,
88 kTraceRtpRtcp = 0x0004,
89 kTraceTransport = 0x0005,
90 kTraceSrtp = 0x0006,
91 kTraceAudioCoding = 0x0007,
92 kTraceAudioMixerServer = 0x0008,
93 kTraceAudioMixerClient = 0x0009,
94 kTraceFile = 0x000a,
95 kTraceAudioProcessing = 0x000b,
96 kTraceVideoCoding = 0x0010,
97 kTraceVideoMixer = 0x0011,
98 kTraceAudioDevice = 0x0012,
99 kTraceVideoRenderer = 0x0014,
100 kTraceVideoCapture = 0x0015,
101 kTraceRemoteBitrateEstimator = 0x0017,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23102};
103
solenbergfaa58c62016-09-01 14:54:53104enum TraceLevel {
105 kTraceNone = 0x0000, // no trace
106 kTraceStateInfo = 0x0001,
107 kTraceWarning = 0x0002,
108 kTraceError = 0x0004,
109 kTraceCritical = 0x0008,
110 kTraceApiCall = 0x0010,
111 kTraceDefault = 0x00ff,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23112
solenbergfaa58c62016-09-01 14:54:53113 kTraceModuleCall = 0x0020,
114 kTraceMemory = 0x0100, // memory info
115 kTraceTimer = 0x0200, // timing info
116 kTraceStream = 0x0400, // "continuous" stream of data
andrew@webrtc.orgb015cbe2012-10-22 18:19:23117
solenbergfaa58c62016-09-01 14:54:53118 // used for debug purposes
119 kTraceDebug = 0x0800, // debug
120 kTraceInfo = 0x1000, // debug info
andrew@webrtc.orgb015cbe2012-10-22 18:19:23121
solenbergfaa58c62016-09-01 14:54:53122 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
123 kTraceTerseInfo = 0x2000,
andrew@webrtc.orgbc687c52012-11-20 07:34:45124
solenbergfaa58c62016-09-01 14:54:53125 kTraceAll = 0xffff
andrew@webrtc.orgb015cbe2012-10-22 18:19:23126};
127
128// External Trace API
andrew@webrtc.orgd75680a2012-11-15 05:33:25129class TraceCallback {
130 public:
131 virtual void Print(TraceLevel level, const char* message, int length) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23132
andrew@webrtc.orgd75680a2012-11-15 05:33:25133 protected:
134 virtual ~TraceCallback() {}
135 TraceCallback() {}
136};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23137
solenbergfaa58c62016-09-01 14:54:53138enum FileFormats {
139 kFileFormatWavFile = 1,
140 kFileFormatCompressedFile = 2,
141 kFileFormatPreencodedFile = 4,
142 kFileFormatPcm16kHzFile = 7,
143 kFileFormatPcm8kHzFile = 8,
lliuu16f74302017-03-31 23:32:28144 kFileFormatPcm32kHzFile = 9
andrew@webrtc.orgb015cbe2012-10-22 18:19:23145};
146
pbosb63d8ad2015-10-19 09:39:06147enum FrameType {
148 kEmptyFrame = 0,
149 kAudioFrameSpeech = 1,
150 kAudioFrameCN = 2,
151 kVideoFrameKey = 3,
152 kVideoFrameDelta = 4,
sprang@webrtc.org5fdd10a2013-12-04 15:09:27153};
154
sprang@webrtc.org46736742013-11-20 16:47:07155// Statistics for an RTCP channel
sprang@webrtc.org2714c792013-10-28 09:21:07156struct RtcpStatistics {
sprang@webrtc.org2714c792013-10-28 09:21:07157 RtcpStatistics()
solenbergfaa58c62016-09-01 14:54:53158 : fraction_lost(0),
159 cumulative_lost(0),
160 extended_max_sequence_number(0),
161 jitter(0) {}
sprang@webrtc.org2714c792013-10-28 09:21:07162
163 uint8_t fraction_lost;
164 uint32_t cumulative_lost;
165 uint32_t extended_max_sequence_number;
166 uint32_t jitter;
sprang@webrtc.org2714c792013-10-28 09:21:07167};
168
sprang@webrtc.org46736742013-11-20 16:47:07169class RtcpStatisticsCallback {
170 public:
171 virtual ~RtcpStatisticsCallback() {}
172
173 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
174 uint32_t ssrc) = 0;
pbos@webrtc.org1a36f782014-12-18 13:50:16175 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07176};
177
asapersson@webrtc.org4a155602014-02-19 11:59:02178// Statistics for RTCP packet types.
179struct RtcpPacketTypeCounter {
180 RtcpPacketTypeCounter()
solenbergfaa58c62016-09-01 14:54:53181 : first_packet_time_ms(-1),
182 nack_packets(0),
183 fir_packets(0),
184 pli_packets(0),
185 nack_requests(0),
186 unique_nack_requests(0) {}
asapersson@webrtc.org4a155602014-02-19 11:59:02187
188 void Add(const RtcpPacketTypeCounter& other) {
189 nack_packets += other.nack_packets;
190 fir_packets += other.fir_packets;
191 pli_packets += other.pli_packets;
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30192 nack_requests += other.nack_requests;
193 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgc76c5532014-12-16 12:03:11194 if (other.first_packet_time_ms != -1 &&
solenbergfaa58c62016-09-01 14:54:53195 (other.first_packet_time_ms < first_packet_time_ms ||
196 first_packet_time_ms == -1)) {
asapersson@webrtc.orgc76c5532014-12-16 12:03:11197 // Use oldest time.
198 first_packet_time_ms = other.first_packet_time_ms;
199 }
200 }
201
sprang22c956d2016-02-24 15:55:00202 void Subtract(const RtcpPacketTypeCounter& other) {
203 nack_packets -= other.nack_packets;
204 fir_packets -= other.fir_packets;
205 pli_packets -= other.pli_packets;
206 nack_requests -= other.nack_requests;
207 unique_nack_requests -= other.unique_nack_requests;
208 if (other.first_packet_time_ms != -1 &&
209 (other.first_packet_time_ms > first_packet_time_ms ||
210 first_packet_time_ms == -1)) {
211 // Use youngest time.
212 first_packet_time_ms = other.first_packet_time_ms;
213 }
214 }
215
asapersson@webrtc.orgc76c5532014-12-16 12:03:11216 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
217 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org4a155602014-02-19 11:59:02218 }
219
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30220 int UniqueNackRequestsInPercent() const {
221 if (nack_requests == 0) {
222 return 0;
223 }
solenbergfaa58c62016-09-01 14:54:53224 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
225 0.5f);
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30226 }
227
solenbergfaa58c62016-09-01 14:54:53228 int64_t first_packet_time_ms; // Time when first packet is sent/received.
229 uint32_t nack_packets; // Number of RTCP NACK packets.
230 uint32_t fir_packets; // Number of RTCP FIR packets.
231 uint32_t pli_packets; // Number of RTCP PLI packets.
232 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30233 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org4a155602014-02-19 11:59:02234};
235
pbos@webrtc.orgeb1c2b52015-02-19 12:47:00236class RtcpPacketTypeCounterObserver {
237 public:
238 virtual ~RtcpPacketTypeCounterObserver() {}
239 virtual void RtcpPacketTypesCounterUpdated(
240 uint32_t ssrc,
241 const RtcpPacketTypeCounter& packet_counter) = 0;
242};
243
asapersson@webrtc.orgc76c5532014-12-16 12:03:11244// Rate statistics for a stream.
sprang@webrtc.org46736742013-11-20 16:47:07245struct BitrateStatistics {
sprang4c991f12016-07-13 16:11:28246 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.org46736742013-11-20 16:47:07247
solenbergfaa58c62016-09-01 14:54:53248 uint32_t bitrate_bps; // Bitrate in bits per second.
249 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.org46736742013-11-20 16:47:07250};
251
252// Callback, used to notify an observer whenever new rates have been estimated.
253class BitrateStatisticsObserver {
254 public:
255 virtual ~BitrateStatisticsObserver() {}
256
sprang4c991f12016-07-13 16:11:28257 virtual void Notify(uint32_t total_bitrate_bps,
258 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org52322672014-11-05 14:05:29259 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07260};
261
pbos@webrtc.org1a36f782014-12-18 13:50:16262struct FrameCounts {
263 FrameCounts() : key_frames(0), delta_frames(0) {}
264 int key_frames;
265 int delta_frames;
266};
267
asapersson@webrtc.orgc76c5532014-12-16 12:03:11268// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.org46736742013-11-20 16:47:07269class FrameCountObserver {
270 public:
sprang@webrtc.org21dc10d2013-11-21 09:09:54271 virtual ~FrameCountObserver() {}
pbos@webrtc.org1a36f782014-12-18 13:50:16272 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
273 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07274};
275
stefan@webrtc.org55b0f2e2014-07-11 13:44:02276// Callback, used to notify an observer whenever the send-side delay is updated.
277class SendSideDelayObserver {
278 public:
279 virtual ~SendSideDelayObserver() {}
280 virtual void SendSideDelayUpdated(int avg_delay_ms,
281 int max_delay_ms,
282 uint32_t ssrc) = 0;
283};
284
asapersson86a285e2016-05-03 06:44:01285// Callback, used to notify an observer whenever a packet is sent to the
286// transport.
287// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
288// Remove SendSideDelayObserver once possible.
289class SendPacketObserver {
290 public:
291 virtual ~SendPacketObserver() {}
292 virtual void OnSendPacket(uint16_t packet_id,
293 int64_t capture_time_ms,
294 uint32_t ssrc) = 0;
295};
296
michaelt57beae32016-11-17 09:38:43297// Callback, used to notify an observer when the overhead per packet
298// has changed.
299class OverheadObserver {
300 public:
301 virtual ~OverheadObserver() = default;
302 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
303};
304
andrew@webrtc.orgb015cbe2012-10-22 18:19:23305// ==================================================================
306// Voice specific types
307// ==================================================================
308
309// Each codec supported can be described by this structure.
mallinath@webrtc.org18c29452014-03-21 00:41:28310struct CodecInst {
311 int pltype;
312 char plname[RTP_PAYLOAD_NAME_SIZE];
313 int plfreq;
314 int pacsize;
Peter Kasting80590d92016-01-13 00:26:35315 size_t channels;
mallinath@webrtc.org18c29452014-03-21 00:41:28316 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
317
318 bool operator==(const CodecInst& other) const {
319 return pltype == other.pltype &&
320 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenbergfaa58c62016-09-01 14:54:53321 plfreq == other.plfreq && pacsize == other.pacsize &&
322 channels == other.channels && rate == other.rate;
mallinath@webrtc.org18c29452014-03-21 00:41:28323 }
324
solenbergfaa58c62016-09-01 14:54:53325 bool operator!=(const CodecInst& other) const { return !(*this == other); }
kwiberg1c0ef6d2016-12-19 14:04:04326
327 friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
328 os << "{pltype: " << ci.pltype;
329 os << ", plname: " << ci.plname;
330 os << ", plfreq: " << ci.plfreq;
331 os << ", pacsize: " << ci.pacsize;
332 os << ", channels: " << ci.channels;
333 os << ", rate: " << ci.rate << "}";
334 return os;
335 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23336};
337
andrew@webrtc.orgb015cbe2012-10-22 18:19:23338// RTP
solenbergfaa58c62016-09-01 14:54:53339enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
andrew@webrtc.orgb015cbe2012-10-22 18:19:23340
solenbergfaa58c62016-09-01 14:54:53341enum PayloadFrequencies {
342 kFreq8000Hz = 8000,
343 kFreq16000Hz = 16000,
344 kFreq32000Hz = 32000
andrew@webrtc.orgb015cbe2012-10-22 18:19:23345};
346
solenbergfaa58c62016-09-01 14:54:53347// Degree of bandwidth reduction.
348enum VadModes {
349 kVadConventional = 0, // lowest reduction
350 kVadAggressiveLow,
351 kVadAggressiveMid,
352 kVadAggressiveHigh // highest reduction
andrew@webrtc.orgb015cbe2012-10-22 18:19:23353};
354
solenbergfaa58c62016-09-01 14:54:53355// NETEQ statistics.
356struct NetworkStatistics {
357 // current jitter buffer size in ms
358 uint16_t currentBufferSize;
359 // preferred (optimal) buffer size in ms
360 uint16_t preferredBufferSize;
361 // adding extra delay due to "peaky jitter"
362 bool jitterPeaksFound;
363 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
364 uint16_t currentPacketLossRate;
365 // Late loss rate; fraction between 0 and 1, scaled to Q14.
366 uint16_t currentDiscardRate;
367 // fraction (of original stream) of synthesized audio inserted through
368 // expansion (in Q14)
369 uint16_t currentExpandRate;
370 // fraction (of original stream) of synthesized speech inserted through
371 // expansion (in Q14)
372 uint16_t currentSpeechExpandRate;
373 // fraction of synthesized speech inserted through pre-emptive expansion
374 // (in Q14)
375 uint16_t currentPreemptiveRate;
376 // fraction of data removed through acceleration (in Q14)
377 uint16_t currentAccelerateRate;
378 // fraction of data coming from secondary decoding (in Q14)
379 uint16_t currentSecondaryDecodedRate;
380 // clock-drift in parts-per-million (negative or positive)
381 int32_t clockDriftPPM;
382 // average packet waiting time in the jitter buffer (ms)
383 int meanWaitingTimeMs;
384 // median packet waiting time in the jitter buffer (ms)
385 int medianWaitingTimeMs;
386 // min packet waiting time in the jitter buffer (ms)
387 int minWaitingTimeMs;
388 // max packet waiting time in the jitter buffer (ms)
389 int maxWaitingTimeMs;
390 // added samples in off mode due to packet loss
391 size_t addedSamples;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23392};
393
wu@webrtc.org79d6daf2013-12-13 19:17:43394// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
395struct AudioDecodingCallStats {
396 AudioDecodingCallStats()
397 : calls_to_silence_generator(0),
398 calls_to_neteq(0),
399 decoded_normal(0),
400 decoded_plc(0),
401 decoded_cng(0),
henrik.lundin4450c272016-09-20 08:47:12402 decoded_plc_cng(0),
403 decoded_muted_output(0) {}
wu@webrtc.org79d6daf2013-12-13 19:17:43404
405 int calls_to_silence_generator; // Number of calls where silence generated,
406 // and NetEq was disengaged from decoding.
solenbergfaa58c62016-09-01 14:54:53407 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org79d6daf2013-12-13 19:17:43408 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenbergfaa58c62016-09-01 14:54:53409 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org79d6daf2013-12-13 19:17:43410 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
411 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin4450c272016-09-20 08:47:12412 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org79d6daf2013-12-13 19:17:43413};
414
andrew@webrtc.orgb015cbe2012-10-22 18:19:23415// ==================================================================
416// Video specific types
417// ==================================================================
418
419// Raw video types
solenbergfaa58c62016-09-01 14:54:53420enum RawVideoType {
421 kVideoI420 = 0,
422 kVideoYV12 = 1,
423 kVideoYUY2 = 2,
424 kVideoUYVY = 3,
425 kVideoIYUV = 4,
426 kVideoARGB = 5,
427 kVideoRGB24 = 6,
428 kVideoRGB565 = 7,
429 kVideoARGB4444 = 8,
430 kVideoARGB1555 = 9,
431 kVideoMJPEG = 10,
432 kVideoNV12 = 11,
433 kVideoNV21 = 12,
434 kVideoBGRA = 13,
435 kVideoUnknown = 99
andrew@webrtc.orgb015cbe2012-10-22 18:19:23436};
437
438// Video codec
solenbergfaa58c62016-09-01 14:54:53439enum { kPayloadNameSize = 32 };
440enum { kMaxSimulcastStreams = 4 };
sprang0ba16d12015-11-02 15:23:20441enum { kMaxSpatialLayers = 5 };
solenbergfaa58c62016-09-01 14:54:53442enum { kMaxTemporalStreams = 4 };
andrew@webrtc.orgb015cbe2012-10-22 18:19:23443
solenbergfaa58c62016-09-01 14:54:53444enum VideoCodecComplexity {
445 kComplexityNormal = 0,
446 kComplexityHigh = 1,
447 kComplexityHigher = 2,
448 kComplexityMax = 3
andrew@webrtc.orgb015cbe2012-10-22 18:19:23449};
450
andrew@webrtc.orgb015cbe2012-10-22 18:19:23451enum VP8ResilienceMode {
452 kResilienceOff, // The stream produced by the encoder requires a
453 // recovery frame (typically a key frame) to be
454 // decodable after a packet loss.
455 kResilientStream, // A stream produced by the encoder is resilient to
456 // packet losses, but packets within a frame subsequent
457 // to a loss can't be decoded.
458 kResilientFrames // Same as kResilientStream but with added resilience
459 // within a frame.
460};
461
Peter Boströmd1460022016-01-19 15:26:16462class TemporalLayersFactory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23463// VP8 specific
mallinath@webrtc.org18c29452014-03-21 00:41:28464struct VideoCodecVP8 {
nisse34282b92017-03-21 08:54:13465 // TODO(nisse): Unused, delete?
solenbergfaa58c62016-09-01 14:54:53466 bool pictureLossIndicationOn;
mallinath@webrtc.org18c29452014-03-21 00:41:28467 VideoCodecComplexity complexity;
solenbergfaa58c62016-09-01 14:54:53468 VP8ResilienceMode resilience;
469 unsigned char numberOfTemporalLayers;
470 bool denoisingOn;
471 bool errorConcealmentOn;
472 bool automaticResizeOn;
473 bool frameDroppingOn;
474 int keyFrameInterval;
Erik Språngfafcfc02016-11-16 15:41:30475 TemporalLayersFactory* tl_factory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23476};
477
asapersson62407972015-07-31 13:10:09478// VP9 specific.
marpan@webrtc.org66373882014-11-01 06:10:48479struct VideoCodecVP9 {
480 VideoCodecComplexity complexity;
asapersson7e1744b2016-12-09 10:35:20481 int resilience;
solenbergfaa58c62016-09-01 14:54:53482 unsigned char numberOfTemporalLayers;
483 bool denoisingOn;
484 bool frameDroppingOn;
485 int keyFrameInterval;
486 bool adaptiveQpMode;
487 bool automaticResizeOn;
488 unsigned char numberOfSpatialLayers;
489 bool flexibleMode;
marpan@webrtc.org66373882014-11-01 06:10:48490};
491
magjedb3b56b22016-11-25 18:06:31492// TODO(magjed): Move this and other H264 related classes out to their own file.
493namespace H264 {
494
495enum Profile {
496 kProfileConstrainedBaseline,
497 kProfileBaseline,
498 kProfileMain,
499 kProfileConstrainedHigh,
500 kProfileHigh,
501};
502
503} // namespace H264
504
stefan@webrtc.org2d4a80c2014-07-04 12:42:07505// H264 specific.
marpan@webrtc.org66373882014-11-01 06:10:48506struct VideoCodecH264 {
solenbergfaa58c62016-09-01 14:54:53507 bool frameDroppingOn;
508 int keyFrameInterval;
marpan@webrtc.org66373882014-11-01 06:10:48509 // These are NULL/0 if not externally negotiated.
510 const uint8_t* spsData;
solenbergfaa58c62016-09-01 14:54:53511 size_t spsLen;
marpan@webrtc.org66373882014-11-01 06:10:48512 const uint8_t* ppsData;
solenbergfaa58c62016-09-01 14:54:53513 size_t ppsLen;
magjedb3b56b22016-11-25 18:06:31514 H264::Profile profile;
stefan@webrtc.org2d4a80c2014-07-04 12:42:07515};
516
andrew@webrtc.orgb015cbe2012-10-22 18:19:23517// Video codec types
marpan@webrtc.org66373882014-11-01 06:10:48518enum VideoCodecType {
519 kVideoCodecVP8,
520 kVideoCodecVP9,
521 kVideoCodecH264,
522 kVideoCodecI420,
523 kVideoCodecRED,
524 kVideoCodecULPFEC,
brandtr8b00e9b2016-11-07 11:03:41525 kVideoCodecFlexfec,
marpan@webrtc.org66373882014-11-01 06:10:48526 kVideoCodecGeneric,
527 kVideoCodecUnknown
andrew@webrtc.orgb015cbe2012-10-22 18:19:23528};
529
Erik Språngfafcfc02016-11-16 15:41:30530// Translates from name of codec to codec type and vice versa.
magjed3fcf7852016-11-22 18:16:57531rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type);
Erik Språngfafcfc02016-11-16 15:41:30532rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name);
533
marpan@webrtc.org66373882014-11-01 06:10:48534union VideoCodecUnion {
solenbergfaa58c62016-09-01 14:54:53535 VideoCodecVP8 VP8;
536 VideoCodecVP9 VP9;
537 VideoCodecH264 H264;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23538};
539
andrew@webrtc.orgb015cbe2012-10-22 18:19:23540// Simulcast is when the same stream is encoded multiple times with different
541// settings such as resolution.
mallinath@webrtc.org18c29452014-03-21 00:41:28542struct SimulcastStream {
solenbergfaa58c62016-09-01 14:54:53543 unsigned short width;
544 unsigned short height;
545 unsigned char numberOfTemporalLayers;
546 unsigned int maxBitrate; // kilobits/sec.
547 unsigned int targetBitrate; // kilobits/sec.
548 unsigned int minBitrate; // kilobits/sec.
549 unsigned int qpMax; // minimum quality
andrew@webrtc.orgb015cbe2012-10-22 18:19:23550};
551
sprang0ba16d12015-11-02 15:23:20552struct SpatialLayer {
553 int scaling_factor_num;
554 int scaling_factor_den;
555 int target_bitrate_bps;
556 // TODO(ivica): Add max_quantizer and min_quantizer?
557};
558
solenbergfaa58c62016-09-01 14:54:53559enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgf4d37882013-02-18 14:40:18560
andrew@webrtc.orgb015cbe2012-10-22 18:19:23561// Common video codec properties
hta078cd6c2016-10-25 16:05:06562class VideoCodec {
563 public:
564 VideoCodec();
565
566 // Public variables. TODO(hta): Make them private with accessors.
solenbergfaa58c62016-09-01 14:54:53567 VideoCodecType codecType;
568 char plName[kPayloadNameSize];
569 unsigned char plType;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23570
solenbergfaa58c62016-09-01 14:54:53571 unsigned short width;
572 unsigned short height;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23573
solenbergfaa58c62016-09-01 14:54:53574 unsigned int startBitrate; // kilobits/sec.
575 unsigned int maxBitrate; // kilobits/sec.
576 unsigned int minBitrate; // kilobits/sec.
577 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3d6910c2014-03-24 12:36:52578
Stefan Holmerc7ca0182017-03-10 14:08:26579 uint32_t maxFramerate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23580
solenbergfaa58c62016-09-01 14:54:53581 unsigned int qpMax;
582 unsigned char numberOfSimulcastStreams;
583 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprang0ba16d12015-11-02 15:23:20584 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgf4d37882013-02-18 14:40:18585
solenbergfaa58c62016-09-01 14:54:53586 VideoCodecMode mode;
587 bool expect_encode_from_texture;
andresp@webrtc.orgee6f8a22013-05-14 08:02:25588
Peter Boströmd1460022016-01-19 15:26:16589 bool operator==(const VideoCodec& other) const = delete;
590 bool operator!=(const VideoCodec& other) const = delete;
hta078cd6c2016-10-25 16:05:06591
592 // Accessors for codec specific information.
593 // There is a const version of each that returns a reference,
594 // and a non-const version that returns a pointer, in order
595 // to allow modification of the parameters.
596 VideoCodecVP8* VP8();
597 const VideoCodecVP8& VP8() const;
598 VideoCodecVP9* VP9();
599 const VideoCodecVP9& VP9() const;
600 VideoCodecH264* H264();
601 const VideoCodecH264& H264() const;
602
hta8ee78142016-11-17 07:23:04603 private:
hta078cd6c2016-10-25 16:05:06604 // TODO(hta): Consider replacing the union with a pointer type.
605 // This will allow removing the VideoCodec* types from this file.
hta8ee78142016-11-17 07:23:04606 VideoCodecUnion codec_specific_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23607};
608
Erik Språngfafcfc02016-11-16 15:41:30609class BitrateAllocation {
610 public:
611 static const uint32_t kMaxBitrateBps;
612 BitrateAllocation();
613
614 bool SetBitrate(size_t spatial_index,
615 size_t temporal_index,
616 uint32_t bitrate_bps);
617
618 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
619
620 // Get the sum of all the temporal layer for a specific spatial layer.
621 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
622
623 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
624 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
625
626 inline bool operator==(const BitrateAllocation& other) const {
627 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
628 }
629 inline bool operator!=(const BitrateAllocation& other) const {
630 return !(*this == other);
631 }
632
633 private:
634 uint32_t sum_;
635 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
636};
637
stefan12764bc2015-11-27 09:02:31638// Bandwidth over-use detector options. These are used to drive
639// experimentation with bandwidth estimation parameters.
640// See modules/remote_bitrate_estimator/overuse_detector.h
tereliused5529d2016-12-27 18:43:01641// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
642// default constructed state. Can we move the relevant variables into that
643// class and delete this? See also disabled warning at line 27
stefan12764bc2015-11-27 09:02:31644struct OverUseDetectorOptions {
645 OverUseDetectorOptions()
solenbergfaa58c62016-09-01 14:54:53646 : initial_slope(8.0 / 512.0),
stefan12764bc2015-11-27 09:02:31647 initial_offset(0),
648 initial_e(),
649 initial_process_noise(),
650 initial_avg_noise(0.0),
651 initial_var_noise(50) {
652 initial_e[0][0] = 100;
653 initial_e[1][1] = 1e-1;
654 initial_e[0][1] = initial_e[1][0] = 0;
655 initial_process_noise[0] = 1e-13;
stefan84d41a32016-03-10 13:13:21656 initial_process_noise[1] = 1e-3;
stefan12764bc2015-11-27 09:02:31657 }
658 double initial_slope;
659 double initial_offset;
660 double initial_e[2][2];
661 double initial_process_noise[2];
662 double initial_avg_noise;
663 double initial_var_noise;
664};
665
wu@webrtc.orgefeb8ce2013-12-13 00:21:03666// This structure will have the information about when packet is actually
667// received by socket.
668struct PacketTime {
henrike@webrtc.org93ae8212014-04-29 17:50:47669 PacketTime() : timestamp(-1), not_before(-1) {}
670 PacketTime(int64_t timestamp, int64_t not_before)
solenbergfaa58c62016-09-01 14:54:53671 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orgefeb8ce2013-12-13 00:21:03672
henrike@webrtc.org93ae8212014-04-29 17:50:47673 int64_t timestamp; // Receive time after socket delivers the data.
674 int64_t not_before; // Earliest possible time the data could have arrived,
675 // indicating the potential error in the |timestamp|
676 // value,in case the system is busy.
677 // For example, the time of the last select() call.
678 // If unknown, this value will be set to zero.
wu@webrtc.orgefeb8ce2013-12-13 00:21:03679};
680
isheriff00cc0452016-06-08 07:24:21681// Minimum and maximum playout delay values from capture to render.
682// These are best effort values.
683//
684// A value < 0 indicates no change from previous valid value.
685//
686// min = max = 0 indicates that the receiver should try and render
687// frame as soon as possible.
688//
689// min = x, max = y indicates that the receiver is free to adapt
690// in the range (x, y) based on network jitter.
691//
692// Note: Given that this gets embedded in a union, it is up-to the owner to
693// initialize these values.
694struct PlayoutDelay {
695 int min_ms;
696 int max_ms;
697};
698
danilchapb7801512017-04-19 09:59:48699// Class to represent RtpStreamId which is a string.
700// Unlike std::string, it can be copied with memcpy and cleared with memset.
701// Empty value represent unset RtpStreamId.
702class StreamId {
703 public:
704 // Stream id is limited to 16 bytes because it is the maximum length
705 // that can be encoded with one-byte header extensions.
706 static constexpr size_t kMaxSize = 16;
707
708 StreamId() { value_[0] = 0; }
709 explicit StreamId(rtc::ArrayView<const char> value) {
710 Set(value.data(), value.size());
711 }
712 StreamId(const StreamId&) = default;
713 StreamId& operator=(const StreamId&) = default;
714
715 bool empty() const { return value_[0] == 0; }
716 const char* data() const { return value_; }
717 size_t size() const { return strnlen(value_, kMaxSize); }
718
719 void Set(rtc::ArrayView<const uint8_t> value) {
720 Set(reinterpret_cast<const char*>(value.data()), value.size());
721 }
722 void Set(const char* data, size_t size);
723
724 friend bool operator==(const StreamId& lhs, const StreamId& rhs) {
725 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
726 }
727 friend bool operator!=(const StreamId& lhs, const StreamId& rhs) {
728 return !(lhs == rhs);
729 }
730
731 private:
732 char value_[kMaxSize];
733};
734
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25735struct RTPHeaderExtension {
sprang@webrtc.org25ec20f2015-03-17 14:33:12736 RTPHeaderExtension();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25737
738 bool hasTransmissionTimeOffset;
739 int32_t transmissionTimeOffset;
740 bool hasAbsoluteSendTime;
741 uint32_t absoluteSendTime;
sprang@webrtc.org25ec20f2015-03-17 14:33:12742 bool hasTransportSequenceNumber;
743 uint16_t transportSequenceNumber;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25744
745 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
746 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
747 bool hasAudioLevel;
Minyueda4c0f02015-08-10 13:08:36748 bool voiceActivity;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25749 uint8_t audioLevel;
guoweis@webrtc.org5f74fcf2015-03-04 22:55:15750
751 // For Coordination of Video Orientation. See
752 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
753 // ts_126114v120700p.pdf
754 bool hasVideoRotation;
magjed78706f42016-09-08 10:24:58755 VideoRotation videoRotation;
isheriff00cc0452016-06-08 07:24:21756
ilnikcb436f62017-04-11 17:34:31757 // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
758 // a corresponding bool flag.
759 bool hasVideoContentType;
760 VideoContentType videoContentType;
761
isheriff00cc0452016-06-08 07:24:21762 PlayoutDelay playout_delay = {-1, -1};
danilchapb7801512017-04-19 09:59:48763
764 // For identification of a stream when ssrc is not signaled. See
765 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
766 // TODO(danilchap): Update url from draft to release version.
767 StreamId stream_id;
768 StreamId repaired_stream_id;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25769};
770
771struct RTPHeader {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22772 RTPHeader();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25773
774 bool markerBit;
775 uint8_t payloadType;
776 uint16_t sequenceNumber;
777 uint32_t timestamp;
778 uint32_t ssrc;
779 uint8_t numCSRCs;
780 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org0ab923a2014-11-20 22:28:14781 size_t paddingLength;
782 size_t headerLength;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25783 int payload_type_frequency;
784 RTPHeaderExtension extension;
785};
786
asapersson@webrtc.org1a8794b2015-02-04 08:34:47787struct RtpPacketCounter {
788 RtpPacketCounter()
solenbergfaa58c62016-09-01 14:54:53789 : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
asapersson@webrtc.org1a8794b2015-02-04 08:34:47790
791 void Add(const RtpPacketCounter& other) {
792 header_bytes += other.header_bytes;
793 payload_bytes += other.payload_bytes;
794 padding_bytes += other.padding_bytes;
795 packets += other.packets;
796 }
797
Erik Språng01cff722016-03-01 08:40:42798 void Subtract(const RtpPacketCounter& other) {
kwibergc1a5e1b2016-11-29 13:30:40799 RTC_DCHECK_GE(header_bytes, other.header_bytes);
Erik Språng01cff722016-03-01 08:40:42800 header_bytes -= other.header_bytes;
kwibergc1a5e1b2016-11-29 13:30:40801 RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
Erik Språng01cff722016-03-01 08:40:42802 payload_bytes -= other.payload_bytes;
kwibergc1a5e1b2016-11-29 13:30:40803 RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
Erik Språng01cff722016-03-01 08:40:42804 padding_bytes -= other.padding_bytes;
kwibergc1a5e1b2016-11-29 13:30:40805 RTC_DCHECK_GE(packets, other.packets);
Erik Språng01cff722016-03-01 08:40:42806 packets -= other.packets;
807 }
808
asapersson@webrtc.org1a8794b2015-02-04 08:34:47809 void AddPacket(size_t packet_length, const RTPHeader& header) {
810 ++packets;
811 header_bytes += header.headerLength;
812 padding_bytes += header.paddingLength;
813 payload_bytes +=
814 packet_length - (header.headerLength + header.paddingLength);
815 }
816
817 size_t TotalBytes() const {
818 return header_bytes + payload_bytes + padding_bytes;
819 }
820
821 size_t header_bytes; // Number of bytes used by RTP headers.
822 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
823 size_t padding_bytes; // Number of padding bytes.
824 uint32_t packets; // Number of packets.
825};
826
827// Data usage statistics for a (rtp) stream.
828struct StreamDataCounters {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22829 StreamDataCounters();
asapersson@webrtc.org1a8794b2015-02-04 08:34:47830
831 void Add(const StreamDataCounters& other) {
832 transmitted.Add(other.transmitted);
833 retransmitted.Add(other.retransmitted);
834 fec.Add(other.fec);
835 if (other.first_packet_time_ms != -1 &&
solenbergfaa58c62016-09-01 14:54:53836 (other.first_packet_time_ms < first_packet_time_ms ||
837 first_packet_time_ms == -1)) {
asapersson@webrtc.org1a8794b2015-02-04 08:34:47838 // Use oldest time.
839 first_packet_time_ms = other.first_packet_time_ms;
840 }
841 }
842
Erik Språng01cff722016-03-01 08:40:42843 void Subtract(const StreamDataCounters& other) {
844 transmitted.Subtract(other.transmitted);
845 retransmitted.Subtract(other.retransmitted);
846 fec.Subtract(other.fec);
847 if (other.first_packet_time_ms != -1 &&
848 (other.first_packet_time_ms > first_packet_time_ms ||
849 first_packet_time_ms == -1)) {
850 // Use youngest time.
851 first_packet_time_ms = other.first_packet_time_ms;
852 }
853 }
854
asapersson@webrtc.org1a8794b2015-02-04 08:34:47855 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
856 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
857 }
858
859 // Returns the number of bytes corresponding to the actual media payload (i.e.
860 // RTP headers, padding, retransmissions and fec packets are excluded).
861 // Note this function does not have meaning for an RTX stream.
862 size_t MediaPayloadBytes() const {
863 return transmitted.payload_bytes - retransmitted.payload_bytes -
864 fec.payload_bytes;
865 }
866
solenbergfaa58c62016-09-01 14:54:53867 int64_t first_packet_time_ms; // Time when first packet is sent/received.
868 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
asapersson@webrtc.org1a8794b2015-02-04 08:34:47869 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
solenbergfaa58c62016-09-01 14:54:53870 RtpPacketCounter fec; // Number of redundancy packets/bytes.
asapersson@webrtc.org1a8794b2015-02-04 08:34:47871};
872
873// Callback, called whenever byte/packet counts have been updated.
874class StreamDataCountersCallback {
875 public:
876 virtual ~StreamDataCountersCallback() {}
877
878 virtual void DataCountersUpdated(const StreamDataCounters& counters,
879 uint32_t ssrc) = 0;
880};
pbosba01e952015-10-02 09:36:56881
882// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
883// RTCP mode is described by RFC 5506.
884enum class RtcpMode { kOff, kCompound, kReducedSize };
885
pbos47a40a32016-05-02 03:18:34886enum NetworkState {
887 kNetworkUp,
888 kNetworkDown,
889};
890
andrew@webrtc.orgb015cbe2012-10-22 18:19:23891} // namespace webrtc
andrew@webrtc.org5cf83f42013-09-09 17:50:10892
893#endif // WEBRTC_COMMON_TYPES_H_