blob: b80635ff8eac288d33008c8cace240a8c1b73bc0 [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
nisseaf916892017-01-10 15:44:2621#include "webrtc/api/video/video_rotation.h"
kwibergb890c95c2016-11-29 13:30:4022#include "webrtc/base/checks.h"
Erik Språng08127a92016-11-16 15:41:3023#include "webrtc/base/optional.h"
andrew@webrtc.orgeda189b2013-09-09 17:50:1024#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:2525
andrew@webrtc.org88b8b0d2012-08-14 00:05:5626#if defined(_MSC_VER)
27// Disable "new behavior: elements of array will be default initialized"
28// warning. Affects OverUseDetectorOptions.
solenberg634b86e2016-09-01 14:54:5329#pragma warning(disable : 4351)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5630#endif
31
kwiberg77eab702016-09-29 00:42:0132#if defined(WEBRTC_EXPORT)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5633#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg77eab702016-09-29 00:42:0134#elif defined(WEBRTC_DLL)
andrew@webrtc.org88b8b0d2012-08-14 00:05:5635#define WEBRTC_DLLEXPORT _declspec(dllimport)
niklase@google.com470e71d2011-07-07 08:21:2536#else
andrew@webrtc.org88b8b0d2012-08-14 00:05:5637#define WEBRTC_DLLEXPORT
niklase@google.com470e71d2011-07-07 08:21:2538#endif
39
40#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:5641#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:2542#endif
43
Peter Boström8b79b072016-02-26 15:31:3744#define RTP_PAYLOAD_NAME_SIZE 32u
henrika@webrtc.orgf75901f2012-01-16 08:45:4245
mallinath@webrtc.org0209e562014-03-21 00:41:2846#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:1047// 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:2556namespace webrtc {
57
tommia6219cc2016-06-15 17:30:1458class RewindableStream {
59 public:
60 virtual ~RewindableStream() {}
61 virtual int Rewind() = 0;
niklase@google.com470e71d2011-07-07 08:21:2562};
63
tommia6219cc2016-06-15 17:30:1464class 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:2576};
77
solenberg634b86e2016-09-01 14:54:5378enum TraceModule {
79 kTraceUndefined = 0,
80 // not a module, triggered from the engine code
81 kTraceVoice = 0x0001,
82 // not a module, triggered from the engine code
83 kTraceVideo = 0x0002,
84 // not a module, triggered from the utility code
85 kTraceUtility = 0x0003,
86 kTraceRtpRtcp = 0x0004,
87 kTraceTransport = 0x0005,
88 kTraceSrtp = 0x0006,
89 kTraceAudioCoding = 0x0007,
90 kTraceAudioMixerServer = 0x0008,
91 kTraceAudioMixerClient = 0x0009,
92 kTraceFile = 0x000a,
93 kTraceAudioProcessing = 0x000b,
94 kTraceVideoCoding = 0x0010,
95 kTraceVideoMixer = 0x0011,
96 kTraceAudioDevice = 0x0012,
97 kTraceVideoRenderer = 0x0014,
98 kTraceVideoCapture = 0x0015,
99 kTraceRemoteBitrateEstimator = 0x0017,
niklase@google.com470e71d2011-07-07 08:21:25100};
101
solenberg634b86e2016-09-01 14:54:53102enum TraceLevel {
103 kTraceNone = 0x0000, // no trace
104 kTraceStateInfo = 0x0001,
105 kTraceWarning = 0x0002,
106 kTraceError = 0x0004,
107 kTraceCritical = 0x0008,
108 kTraceApiCall = 0x0010,
109 kTraceDefault = 0x00ff,
niklase@google.com470e71d2011-07-07 08:21:25110
solenberg634b86e2016-09-01 14:54:53111 kTraceModuleCall = 0x0020,
112 kTraceMemory = 0x0100, // memory info
113 kTraceTimer = 0x0200, // timing info
114 kTraceStream = 0x0400, // "continuous" stream of data
niklase@google.com470e71d2011-07-07 08:21:25115
solenberg634b86e2016-09-01 14:54:53116 // used for debug purposes
117 kTraceDebug = 0x0800, // debug
118 kTraceInfo = 0x1000, // debug info
niklase@google.com470e71d2011-07-07 08:21:25119
solenberg634b86e2016-09-01 14:54:53120 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
121 kTraceTerseInfo = 0x2000,
andrew@webrtc.org655d8f52012-11-20 07:34:45122
solenberg634b86e2016-09-01 14:54:53123 kTraceAll = 0xffff
niklase@google.com470e71d2011-07-07 08:21:25124};
125
126// External Trace API
andrew@webrtc.org23ec30b2012-11-15 05:33:25127class TraceCallback {
128 public:
129 virtual void Print(TraceLevel level, const char* message, int length) = 0;
niklase@google.com470e71d2011-07-07 08:21:25130
andrew@webrtc.org23ec30b2012-11-15 05:33:25131 protected:
132 virtual ~TraceCallback() {}
133 TraceCallback() {}
134};
niklase@google.com470e71d2011-07-07 08:21:25135
solenberg634b86e2016-09-01 14:54:53136enum FileFormats {
137 kFileFormatWavFile = 1,
138 kFileFormatCompressedFile = 2,
139 kFileFormatPreencodedFile = 4,
140 kFileFormatPcm16kHzFile = 7,
141 kFileFormatPcm8kHzFile = 8,
142 kFileFormatPcm32kHzFile = 9
niklase@google.com470e71d2011-07-07 08:21:25143};
144
pbos22993e12015-10-19 09:39:06145enum FrameType {
146 kEmptyFrame = 0,
147 kAudioFrameSpeech = 1,
148 kAudioFrameCN = 2,
149 kVideoFrameKey = 3,
150 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27151};
152
sprang@webrtc.orgdc50aae2013-11-20 16:47:07153// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07154struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07155 RtcpStatistics()
solenberg634b86e2016-09-01 14:54:53156 : fraction_lost(0),
157 cumulative_lost(0),
158 extended_max_sequence_number(0),
159 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07160
161 uint8_t fraction_lost;
162 uint32_t cumulative_lost;
163 uint32_t extended_max_sequence_number;
164 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07165};
166
sprang@webrtc.orgdc50aae2013-11-20 16:47:07167class RtcpStatisticsCallback {
168 public:
169 virtual ~RtcpStatisticsCallback() {}
170
171 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
172 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16173 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07174};
175
asapersson@webrtc.org8098e072014-02-19 11:59:02176// Statistics for RTCP packet types.
177struct RtcpPacketTypeCounter {
178 RtcpPacketTypeCounter()
solenberg634b86e2016-09-01 14:54:53179 : first_packet_time_ms(-1),
180 nack_packets(0),
181 fir_packets(0),
182 pli_packets(0),
183 nack_requests(0),
184 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02185
186 void Add(const RtcpPacketTypeCounter& other) {
187 nack_packets += other.nack_packets;
188 fir_packets += other.fir_packets;
189 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30190 nack_requests += other.nack_requests;
191 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11192 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 14:54:53193 (other.first_packet_time_ms < first_packet_time_ms ||
194 first_packet_time_ms == -1)) {
asapersson@webrtc.orgd08d3892014-12-16 12:03:11195 // Use oldest time.
196 first_packet_time_ms = other.first_packet_time_ms;
197 }
198 }
199
sprang07fb9be2016-02-24 15:55:00200 void Subtract(const RtcpPacketTypeCounter& other) {
201 nack_packets -= other.nack_packets;
202 fir_packets -= other.fir_packets;
203 pli_packets -= other.pli_packets;
204 nack_requests -= other.nack_requests;
205 unique_nack_requests -= other.unique_nack_requests;
206 if (other.first_packet_time_ms != -1 &&
207 (other.first_packet_time_ms > first_packet_time_ms ||
208 first_packet_time_ms == -1)) {
209 // Use youngest time.
210 first_packet_time_ms = other.first_packet_time_ms;
211 }
212 }
213
asapersson@webrtc.orgd08d3892014-12-16 12:03:11214 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
215 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org8098e072014-02-19 11:59:02216 }
217
asapersson@webrtc.org2dd31342014-10-29 12:42:30218 int UniqueNackRequestsInPercent() const {
219 if (nack_requests == 0) {
220 return 0;
221 }
solenberg634b86e2016-09-01 14:54:53222 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
223 0.5f);
asapersson@webrtc.org2dd31342014-10-29 12:42:30224 }
225
solenberg634b86e2016-09-01 14:54:53226 int64_t first_packet_time_ms; // Time when first packet is sent/received.
227 uint32_t nack_packets; // Number of RTCP NACK packets.
228 uint32_t fir_packets; // Number of RTCP FIR packets.
229 uint32_t pli_packets; // Number of RTCP PLI packets.
230 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2dd31342014-10-29 12:42:30231 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02232};
233
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00234class RtcpPacketTypeCounterObserver {
235 public:
236 virtual ~RtcpPacketTypeCounterObserver() {}
237 virtual void RtcpPacketTypesCounterUpdated(
238 uint32_t ssrc,
239 const RtcpPacketTypeCounter& packet_counter) = 0;
240};
241
asapersson@webrtc.orgd08d3892014-12-16 12:03:11242// Rate statistics for a stream.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07243struct BitrateStatistics {
sprangcd349d92016-07-13 16:11:28244 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.orgdc50aae2013-11-20 16:47:07245
solenberg634b86e2016-09-01 14:54:53246 uint32_t bitrate_bps; // Bitrate in bits per second.
247 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07248};
249
250// Callback, used to notify an observer whenever new rates have been estimated.
251class BitrateStatisticsObserver {
252 public:
253 virtual ~BitrateStatisticsObserver() {}
254
sprangcd349d92016-07-13 16:11:28255 virtual void Notify(uint32_t total_bitrate_bps,
256 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org0bae1fa2014-11-05 14:05:29257 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07258};
259
pbos@webrtc.orgce4e9a32014-12-18 13:50:16260struct FrameCounts {
261 FrameCounts() : key_frames(0), delta_frames(0) {}
262 int key_frames;
263 int delta_frames;
264};
265
asapersson@webrtc.orgd08d3892014-12-16 12:03:11266// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07267class FrameCountObserver {
268 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54269 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16270 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
271 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07272};
273
stefan@webrtc.org168f23f2014-07-11 13:44:02274// Callback, used to notify an observer whenever the send-side delay is updated.
275class SendSideDelayObserver {
276 public:
277 virtual ~SendSideDelayObserver() {}
278 virtual void SendSideDelayUpdated(int avg_delay_ms,
279 int max_delay_ms,
280 uint32_t ssrc) = 0;
281};
282
asapersson35151f32016-05-03 06:44:01283// Callback, used to notify an observer whenever a packet is sent to the
284// transport.
285// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
286// Remove SendSideDelayObserver once possible.
287class SendPacketObserver {
288 public:
289 virtual ~SendPacketObserver() {}
290 virtual void OnSendPacket(uint16_t packet_id,
291 int64_t capture_time_ms,
292 uint32_t ssrc) = 0;
293};
294
michaelt4da30442016-11-17 09:38:43295// Callback, used to notify an observer when the overhead per packet
296// has changed.
297class OverheadObserver {
298 public:
299 virtual ~OverheadObserver() = default;
300 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
301};
302
niklase@google.com470e71d2011-07-07 08:21:25303// ==================================================================
304// Voice specific types
305// ==================================================================
306
307// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28308struct CodecInst {
309 int pltype;
310 char plname[RTP_PAYLOAD_NAME_SIZE];
311 int plfreq;
312 int pacsize;
Peter Kasting69558702016-01-13 00:26:35313 size_t channels;
mallinath@webrtc.org0209e562014-03-21 00:41:28314 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
315
316 bool operator==(const CodecInst& other) const {
317 return pltype == other.pltype &&
318 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenberg634b86e2016-09-01 14:54:53319 plfreq == other.plfreq && pacsize == other.pacsize &&
320 channels == other.channels && rate == other.rate;
mallinath@webrtc.org0209e562014-03-21 00:41:28321 }
322
solenberg634b86e2016-09-01 14:54:53323 bool operator!=(const CodecInst& other) const { return !(*this == other); }
kwiberg5bf4e082016-12-19 14:04:04324
325 friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) {
326 os << "{pltype: " << ci.pltype;
327 os << ", plname: " << ci.plname;
328 os << ", plfreq: " << ci.plfreq;
329 os << ", pacsize: " << ci.pacsize;
330 os << ", channels: " << ci.channels;
331 os << ", rate: " << ci.rate << "}";
332 return os;
333 }
niklase@google.com470e71d2011-07-07 08:21:25334};
335
niklase@google.com470e71d2011-07-07 08:21:25336// RTP
solenberg634b86e2016-09-01 14:54:53337enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
niklase@google.com470e71d2011-07-07 08:21:25338
solenberg634b86e2016-09-01 14:54:53339enum PayloadFrequencies {
340 kFreq8000Hz = 8000,
341 kFreq16000Hz = 16000,
342 kFreq32000Hz = 32000
niklase@google.com470e71d2011-07-07 08:21:25343};
344
solenberg634b86e2016-09-01 14:54:53345// Degree of bandwidth reduction.
346enum VadModes {
347 kVadConventional = 0, // lowest reduction
348 kVadAggressiveLow,
349 kVadAggressiveMid,
350 kVadAggressiveHigh // highest reduction
niklase@google.com470e71d2011-07-07 08:21:25351};
352
solenberg634b86e2016-09-01 14:54:53353// NETEQ statistics.
354struct NetworkStatistics {
355 // current jitter buffer size in ms
356 uint16_t currentBufferSize;
357 // preferred (optimal) buffer size in ms
358 uint16_t preferredBufferSize;
359 // adding extra delay due to "peaky jitter"
360 bool jitterPeaksFound;
361 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
362 uint16_t currentPacketLossRate;
363 // Late loss rate; fraction between 0 and 1, scaled to Q14.
364 uint16_t currentDiscardRate;
365 // fraction (of original stream) of synthesized audio inserted through
366 // expansion (in Q14)
367 uint16_t currentExpandRate;
368 // fraction (of original stream) of synthesized speech inserted through
369 // expansion (in Q14)
370 uint16_t currentSpeechExpandRate;
371 // fraction of synthesized speech inserted through pre-emptive expansion
372 // (in Q14)
373 uint16_t currentPreemptiveRate;
374 // fraction of data removed through acceleration (in Q14)
375 uint16_t currentAccelerateRate;
376 // fraction of data coming from secondary decoding (in Q14)
377 uint16_t currentSecondaryDecodedRate;
378 // clock-drift in parts-per-million (negative or positive)
379 int32_t clockDriftPPM;
380 // average packet waiting time in the jitter buffer (ms)
381 int meanWaitingTimeMs;
382 // median packet waiting time in the jitter buffer (ms)
383 int medianWaitingTimeMs;
384 // min packet waiting time in the jitter buffer (ms)
385 int minWaitingTimeMs;
386 // max packet waiting time in the jitter buffer (ms)
387 int maxWaitingTimeMs;
388 // added samples in off mode due to packet loss
389 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25390};
391
wu@webrtc.org24301a62013-12-13 19:17:43392// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
393struct AudioDecodingCallStats {
394 AudioDecodingCallStats()
395 : calls_to_silence_generator(0),
396 calls_to_neteq(0),
397 decoded_normal(0),
398 decoded_plc(0),
399 decoded_cng(0),
henrik.lundin63489782016-09-20 08:47:12400 decoded_plc_cng(0),
401 decoded_muted_output(0) {}
wu@webrtc.org24301a62013-12-13 19:17:43402
403 int calls_to_silence_generator; // Number of calls where silence generated,
404 // and NetEq was disengaged from decoding.
solenberg634b86e2016-09-01 14:54:53405 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org24301a62013-12-13 19:17:43406 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenberg634b86e2016-09-01 14:54:53407 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org24301a62013-12-13 19:17:43408 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
409 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin63489782016-09-20 08:47:12410 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org24301a62013-12-13 19:17:43411};
412
solenberg634b86e2016-09-01 14:54:53413// Type of Noise Suppression.
414enum NsModes {
415 kNsUnchanged = 0, // previously set mode
416 kNsDefault, // platform default
417 kNsConference, // conferencing default
418 kNsLowSuppression, // lowest suppression
419 kNsModerateSuppression,
420 kNsHighSuppression,
421 kNsVeryHighSuppression, // highest suppression
niklase@google.com470e71d2011-07-07 08:21:25422};
423
solenberg634b86e2016-09-01 14:54:53424// Type of Automatic Gain Control.
425enum AgcModes {
426 kAgcUnchanged = 0, // previously set mode
427 kAgcDefault, // platform default
428 // adaptive mode for use when analog volume control exists (e.g. for
429 // PC softphone)
430 kAgcAdaptiveAnalog,
431 // scaling takes place in the digital domain (e.g. for conference servers
432 // and embedded devices)
433 kAgcAdaptiveDigital,
434 // can be used on embedded devices where the capture signal level
435 // is predictable
436 kAgcFixedDigital
niklase@google.com470e71d2011-07-07 08:21:25437};
438
solenberg634b86e2016-09-01 14:54:53439// Type of Echo Control.
440enum EcModes {
441 kEcUnchanged = 0, // previously set mode
442 kEcDefault, // platform default
443 kEcConference, // conferencing default (aggressive AEC)
444 kEcAec, // Acoustic Echo Cancellation
445 kEcAecm, // AEC mobile
niklase@google.com470e71d2011-07-07 08:21:25446};
447
solenberg634b86e2016-09-01 14:54:53448// Mode of AECM.
449enum AecmModes {
450 kAecmQuietEarpieceOrHeadset = 0,
451 // Quiet earpiece or headset use
452 kAecmEarpiece, // most earpiece use
453 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
454 kAecmSpeakerphone, // most speakerphone use (default)
455 kAecmLoudSpeakerphone // Loud speakerphone
niklase@google.com470e71d2011-07-07 08:21:25456};
457
solenbergbe5163c2016-08-31 21:48:53458// AGC configuration parameters
solenberg634b86e2016-09-01 14:54:53459struct AgcConfig {
460 unsigned short targetLeveldBOv;
461 unsigned short digitalCompressionGaindB;
462 bool limiterEnable;
solenbergbe5163c2016-08-31 21:48:53463};
niklase@google.com470e71d2011-07-07 08:21:25464
solenberg634b86e2016-09-01 14:54:53465enum StereoChannel { kStereoLeft = 0, kStereoRight, kStereoBoth };
niklase@google.com470e71d2011-07-07 08:21:25466
467// Audio device layers
solenberg634b86e2016-09-01 14:54:53468enum AudioLayers {
469 kAudioPlatformDefault = 0,
solenberg634b86e2016-09-01 14:54:53470 kAudioWindowsCore = 2,
471 kAudioLinuxAlsa = 3,
472 kAudioLinuxPulse = 4
niklase@google.com470e71d2011-07-07 08:21:25473};
474
niklase@google.com470e71d2011-07-07 08:21:25475// ==================================================================
476// Video specific types
477// ==================================================================
478
479// Raw video types
solenberg634b86e2016-09-01 14:54:53480enum RawVideoType {
481 kVideoI420 = 0,
482 kVideoYV12 = 1,
483 kVideoYUY2 = 2,
484 kVideoUYVY = 3,
485 kVideoIYUV = 4,
486 kVideoARGB = 5,
487 kVideoRGB24 = 6,
488 kVideoRGB565 = 7,
489 kVideoARGB4444 = 8,
490 kVideoARGB1555 = 9,
491 kVideoMJPEG = 10,
492 kVideoNV12 = 11,
493 kVideoNV21 = 12,
494 kVideoBGRA = 13,
495 kVideoUnknown = 99
niklase@google.com470e71d2011-07-07 08:21:25496};
497
498// Video codec
solenberg634b86e2016-09-01 14:54:53499enum { kConfigParameterSize = 128 };
500enum { kPayloadNameSize = 32 };
501enum { kMaxSimulcastStreams = 4 };
sprangce4aef12015-11-02 15:23:20502enum { kMaxSpatialLayers = 5 };
solenberg634b86e2016-09-01 14:54:53503enum { kMaxTemporalStreams = 4 };
niklase@google.com470e71d2011-07-07 08:21:25504
solenberg634b86e2016-09-01 14:54:53505enum VideoCodecComplexity {
506 kComplexityNormal = 0,
507 kComplexityHigh = 1,
508 kComplexityHigher = 2,
509 kComplexityMax = 3
niklase@google.com470e71d2011-07-07 08:21:25510};
511
stefan@webrtc.orgefd0a482011-12-29 10:12:35512enum VP8ResilienceMode {
513 kResilienceOff, // The stream produced by the encoder requires a
514 // recovery frame (typically a key frame) to be
515 // decodable after a packet loss.
516 kResilientStream, // A stream produced by the encoder is resilient to
517 // packet losses, but packets within a frame subsequent
518 // to a loss can't be decoded.
519 kResilientFrames // Same as kResilientStream but with added resilience
520 // within a frame.
521};
522
Peter Boström7b971e72016-01-19 15:26:16523class TemporalLayersFactory;
niklase@google.com470e71d2011-07-07 08:21:25524// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28525struct VideoCodecVP8 {
solenberg634b86e2016-09-01 14:54:53526 bool pictureLossIndicationOn;
527 bool feedbackModeOn;
mallinath@webrtc.org0209e562014-03-21 00:41:28528 VideoCodecComplexity complexity;
solenberg634b86e2016-09-01 14:54:53529 VP8ResilienceMode resilience;
530 unsigned char numberOfTemporalLayers;
531 bool denoisingOn;
532 bool errorConcealmentOn;
533 bool automaticResizeOn;
534 bool frameDroppingOn;
535 int keyFrameInterval;
Erik Språng08127a92016-11-16 15:41:30536 TemporalLayersFactory* tl_factory;
niklase@google.com470e71d2011-07-07 08:21:25537};
538
asaperssona9455ab2015-07-31 13:10:09539// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48540struct VideoCodecVP9 {
541 VideoCodecComplexity complexity;
asaperssona90799d2016-12-09 10:35:20542 int resilience;
solenberg634b86e2016-09-01 14:54:53543 unsigned char numberOfTemporalLayers;
544 bool denoisingOn;
545 bool frameDroppingOn;
546 int keyFrameInterval;
547 bool adaptiveQpMode;
548 bool automaticResizeOn;
549 unsigned char numberOfSpatialLayers;
550 bool flexibleMode;
marpan@webrtc.org5b883172014-11-01 06:10:48551};
552
magjede69a1a92016-11-25 18:06:31553// TODO(magjed): Move this and other H264 related classes out to their own file.
554namespace H264 {
555
556enum Profile {
557 kProfileConstrainedBaseline,
558 kProfileBaseline,
559 kProfileMain,
560 kProfileConstrainedHigh,
561 kProfileHigh,
562};
563
564} // namespace H264
565
stefan@webrtc.orgb9f54532014-07-04 12:42:07566// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48567struct VideoCodecH264 {
solenberg634b86e2016-09-01 14:54:53568 bool frameDroppingOn;
569 int keyFrameInterval;
marpan@webrtc.org5b883172014-11-01 06:10:48570 // These are NULL/0 if not externally negotiated.
571 const uint8_t* spsData;
solenberg634b86e2016-09-01 14:54:53572 size_t spsLen;
marpan@webrtc.org5b883172014-11-01 06:10:48573 const uint8_t* ppsData;
solenberg634b86e2016-09-01 14:54:53574 size_t ppsLen;
magjede69a1a92016-11-25 18:06:31575 H264::Profile profile;
stefan@webrtc.orgb9f54532014-07-04 12:42:07576};
577
niklase@google.com470e71d2011-07-07 08:21:25578// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48579enum VideoCodecType {
580 kVideoCodecVP8,
581 kVideoCodecVP9,
582 kVideoCodecH264,
583 kVideoCodecI420,
584 kVideoCodecRED,
585 kVideoCodecULPFEC,
brandtr87d7d772016-11-07 11:03:41586 kVideoCodecFlexfec,
marpan@webrtc.org5b883172014-11-01 06:10:48587 kVideoCodecGeneric,
588 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25589};
590
Erik Språng08127a92016-11-16 15:41:30591// Translates from name of codec to codec type and vice versa.
magjed10165ab2016-11-22 18:16:57592rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type);
Erik Språng08127a92016-11-16 15:41:30593rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name);
594
marpan@webrtc.org5b883172014-11-01 06:10:48595union VideoCodecUnion {
solenberg634b86e2016-09-01 14:54:53596 VideoCodecVP8 VP8;
597 VideoCodecVP9 VP9;
598 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25599};
600
phoglund@webrtc.org8bfee842012-02-17 09:32:48601// Simulcast is when the same stream is encoded multiple times with different
602// settings such as resolution.
mallinath@webrtc.org0209e562014-03-21 00:41:28603struct SimulcastStream {
solenberg634b86e2016-09-01 14:54:53604 unsigned short width;
605 unsigned short height;
606 unsigned char numberOfTemporalLayers;
607 unsigned int maxBitrate; // kilobits/sec.
608 unsigned int targetBitrate; // kilobits/sec.
609 unsigned int minBitrate; // kilobits/sec.
610 unsigned int qpMax; // minimum quality
pwestin@webrtc.org1da1ce02011-10-13 15:19:55611};
612
sprangce4aef12015-11-02 15:23:20613struct SpatialLayer {
614 int scaling_factor_num;
615 int scaling_factor_den;
616 int target_bitrate_bps;
617 // TODO(ivica): Add max_quantizer and min_quantizer?
618};
619
solenberg634b86e2016-09-01 14:54:53620enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgeb917922013-02-18 14:40:18621
niklase@google.com470e71d2011-07-07 08:21:25622// Common video codec properties
hta257dc392016-10-25 16:05:06623class VideoCodec {
624 public:
625 VideoCodec();
626
627 // Public variables. TODO(hta): Make them private with accessors.
solenberg634b86e2016-09-01 14:54:53628 VideoCodecType codecType;
629 char plName[kPayloadNameSize];
630 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25631
solenberg634b86e2016-09-01 14:54:53632 unsigned short width;
633 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25634
solenberg634b86e2016-09-01 14:54:53635 unsigned int startBitrate; // kilobits/sec.
636 unsigned int maxBitrate; // kilobits/sec.
637 unsigned int minBitrate; // kilobits/sec.
638 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52639
Stefan Holmer144475b2017-03-10 14:08:26640 uint32_t maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25641
solenberg634b86e2016-09-01 14:54:53642 unsigned int qpMax;
643 unsigned char numberOfSimulcastStreams;
644 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 15:23:20645 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18646
solenberg634b86e2016-09-01 14:54:53647 VideoCodecMode mode;
648 bool expect_encode_from_texture;
andresp@webrtc.org185bae42013-05-14 08:02:25649
Peter Boström7b971e72016-01-19 15:26:16650 bool operator==(const VideoCodec& other) const = delete;
651 bool operator!=(const VideoCodec& other) const = delete;
hta257dc392016-10-25 16:05:06652
653 // Accessors for codec specific information.
654 // There is a const version of each that returns a reference,
655 // and a non-const version that returns a pointer, in order
656 // to allow modification of the parameters.
657 VideoCodecVP8* VP8();
658 const VideoCodecVP8& VP8() const;
659 VideoCodecVP9* VP9();
660 const VideoCodecVP9& VP9() const;
661 VideoCodecH264* H264();
662 const VideoCodecH264& H264() const;
663
hta527d3472016-11-17 07:23:04664 private:
hta257dc392016-10-25 16:05:06665 // TODO(hta): Consider replacing the union with a pointer type.
666 // This will allow removing the VideoCodec* types from this file.
hta527d3472016-11-17 07:23:04667 VideoCodecUnion codec_specific_;
niklase@google.com470e71d2011-07-07 08:21:25668};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04669
Erik Språng08127a92016-11-16 15:41:30670class BitrateAllocation {
671 public:
672 static const uint32_t kMaxBitrateBps;
673 BitrateAllocation();
674
675 bool SetBitrate(size_t spatial_index,
676 size_t temporal_index,
677 uint32_t bitrate_bps);
678
679 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
680
681 // Get the sum of all the temporal layer for a specific spatial layer.
682 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
683
684 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
685 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
686
687 inline bool operator==(const BitrateAllocation& other) const {
688 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
689 }
690 inline bool operator!=(const BitrateAllocation& other) const {
691 return !(*this == other);
692 }
693
694 private:
695 uint32_t sum_;
696 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
697};
698
stefan64c0a0a2015-11-27 09:02:31699// Bandwidth over-use detector options. These are used to drive
700// experimentation with bandwidth estimation parameters.
701// See modules/remote_bitrate_estimator/overuse_detector.h
terelius84f83f82016-12-27 18:43:01702// TODO(terelius): This is only used in overuse_estimator.cc, and only in the
703// default constructed state. Can we move the relevant variables into that
704// class and delete this? See also disabled warning at line 27
stefan64c0a0a2015-11-27 09:02:31705struct OverUseDetectorOptions {
706 OverUseDetectorOptions()
solenberg634b86e2016-09-01 14:54:53707 : initial_slope(8.0 / 512.0),
stefan64c0a0a2015-11-27 09:02:31708 initial_offset(0),
709 initial_e(),
710 initial_process_noise(),
711 initial_avg_noise(0.0),
712 initial_var_noise(50) {
713 initial_e[0][0] = 100;
714 initial_e[1][1] = 1e-1;
715 initial_e[0][1] = initial_e[1][0] = 0;
716 initial_process_noise[0] = 1e-13;
stefan1069cac2016-03-10 13:13:21717 initial_process_noise[1] = 1e-3;
stefan64c0a0a2015-11-27 09:02:31718 }
719 double initial_slope;
720 double initial_offset;
721 double initial_e[2][2];
722 double initial_process_noise[2];
723 double initial_avg_noise;
724 double initial_var_noise;
725};
726
wu@webrtc.orga9890802013-12-13 00:21:03727// This structure will have the information about when packet is actually
728// received by socket.
729struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47730 PacketTime() : timestamp(-1), not_before(-1) {}
731 PacketTime(int64_t timestamp, int64_t not_before)
solenberg634b86e2016-09-01 14:54:53732 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orga9890802013-12-13 00:21:03733
henrike@webrtc.org82d3cb62014-04-29 17:50:47734 int64_t timestamp; // Receive time after socket delivers the data.
735 int64_t not_before; // Earliest possible time the data could have arrived,
736 // indicating the potential error in the |timestamp|
737 // value,in case the system is busy.
738 // For example, the time of the last select() call.
739 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03740};
741
isheriff6b4b5f32016-06-08 07:24:21742// Minimum and maximum playout delay values from capture to render.
743// These are best effort values.
744//
745// A value < 0 indicates no change from previous valid value.
746//
747// min = max = 0 indicates that the receiver should try and render
748// frame as soon as possible.
749//
750// min = x, max = y indicates that the receiver is free to adapt
751// in the range (x, y) based on network jitter.
752//
753// Note: Given that this gets embedded in a union, it is up-to the owner to
754// initialize these values.
755struct PlayoutDelay {
756 int min_ms;
757 int max_ms;
758};
759
solenberg@webrtc.orgb1f50102014-03-24 10:38:25760struct RTPHeaderExtension {
sprang@webrtc.org30933902015-03-17 14:33:12761 RTPHeaderExtension();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25762
763 bool hasTransmissionTimeOffset;
764 int32_t transmissionTimeOffset;
765 bool hasAbsoluteSendTime;
766 uint32_t absoluteSendTime;
sprang@webrtc.org30933902015-03-17 14:33:12767 bool hasTransportSequenceNumber;
768 uint16_t transportSequenceNumber;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25769
770 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
771 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
772 bool hasAudioLevel;
Minyue4cee4192015-08-10 13:08:36773 bool voiceActivity;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25774 uint8_t audioLevel;
guoweis@webrtc.org45362892015-03-04 22:55:15775
776 // For Coordination of Video Orientation. See
777 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
778 // ts_126114v120700p.pdf
779 bool hasVideoRotation;
magjed71eb61c2016-09-08 10:24:58780 VideoRotation videoRotation;
isheriff6b4b5f32016-06-08 07:24:21781
782 PlayoutDelay playout_delay = {-1, -1};
solenberg@webrtc.orgb1f50102014-03-24 10:38:25783};
784
785struct RTPHeader {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22786 RTPHeader();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25787
788 bool markerBit;
789 uint8_t payloadType;
790 uint16_t sequenceNumber;
791 uint32_t timestamp;
792 uint32_t ssrc;
793 uint8_t numCSRCs;
794 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org4591fbd2014-11-20 22:28:14795 size_t paddingLength;
796 size_t headerLength;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25797 int payload_type_frequency;
798 RTPHeaderExtension extension;
799};
800
asapersson@webrtc.org44149392015-02-04 08:34:47801struct RtpPacketCounter {
802 RtpPacketCounter()
solenberg634b86e2016-09-01 14:54:53803 : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
asapersson@webrtc.org44149392015-02-04 08:34:47804
805 void Add(const RtpPacketCounter& other) {
806 header_bytes += other.header_bytes;
807 payload_bytes += other.payload_bytes;
808 padding_bytes += other.padding_bytes;
809 packets += other.packets;
810 }
811
Erik Språng22c2b482016-03-01 08:40:42812 void Subtract(const RtpPacketCounter& other) {
kwibergb890c95c2016-11-29 13:30:40813 RTC_DCHECK_GE(header_bytes, other.header_bytes);
Erik Språng22c2b482016-03-01 08:40:42814 header_bytes -= other.header_bytes;
kwibergb890c95c2016-11-29 13:30:40815 RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
Erik Språng22c2b482016-03-01 08:40:42816 payload_bytes -= other.payload_bytes;
kwibergb890c95c2016-11-29 13:30:40817 RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
Erik Språng22c2b482016-03-01 08:40:42818 padding_bytes -= other.padding_bytes;
kwibergb890c95c2016-11-29 13:30:40819 RTC_DCHECK_GE(packets, other.packets);
Erik Språng22c2b482016-03-01 08:40:42820 packets -= other.packets;
821 }
822
asapersson@webrtc.org44149392015-02-04 08:34:47823 void AddPacket(size_t packet_length, const RTPHeader& header) {
824 ++packets;
825 header_bytes += header.headerLength;
826 padding_bytes += header.paddingLength;
827 payload_bytes +=
828 packet_length - (header.headerLength + header.paddingLength);
829 }
830
831 size_t TotalBytes() const {
832 return header_bytes + payload_bytes + padding_bytes;
833 }
834
835 size_t header_bytes; // Number of bytes used by RTP headers.
836 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
837 size_t padding_bytes; // Number of padding bytes.
838 uint32_t packets; // Number of packets.
839};
840
841// Data usage statistics for a (rtp) stream.
842struct StreamDataCounters {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22843 StreamDataCounters();
asapersson@webrtc.org44149392015-02-04 08:34:47844
845 void Add(const StreamDataCounters& other) {
846 transmitted.Add(other.transmitted);
847 retransmitted.Add(other.retransmitted);
848 fec.Add(other.fec);
849 if (other.first_packet_time_ms != -1 &&
solenberg634b86e2016-09-01 14:54:53850 (other.first_packet_time_ms < first_packet_time_ms ||
851 first_packet_time_ms == -1)) {
asapersson@webrtc.org44149392015-02-04 08:34:47852 // Use oldest time.
853 first_packet_time_ms = other.first_packet_time_ms;
854 }
855 }
856
Erik Språng22c2b482016-03-01 08:40:42857 void Subtract(const StreamDataCounters& other) {
858 transmitted.Subtract(other.transmitted);
859 retransmitted.Subtract(other.retransmitted);
860 fec.Subtract(other.fec);
861 if (other.first_packet_time_ms != -1 &&
862 (other.first_packet_time_ms > first_packet_time_ms ||
863 first_packet_time_ms == -1)) {
864 // Use youngest time.
865 first_packet_time_ms = other.first_packet_time_ms;
866 }
867 }
868
asapersson@webrtc.org44149392015-02-04 08:34:47869 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
870 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
871 }
872
873 // Returns the number of bytes corresponding to the actual media payload (i.e.
874 // RTP headers, padding, retransmissions and fec packets are excluded).
875 // Note this function does not have meaning for an RTX stream.
876 size_t MediaPayloadBytes() const {
877 return transmitted.payload_bytes - retransmitted.payload_bytes -
878 fec.payload_bytes;
879 }
880
solenberg634b86e2016-09-01 14:54:53881 int64_t first_packet_time_ms; // Time when first packet is sent/received.
882 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47883 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
solenberg634b86e2016-09-01 14:54:53884 RtpPacketCounter fec; // Number of redundancy packets/bytes.
asapersson@webrtc.org44149392015-02-04 08:34:47885};
886
887// Callback, called whenever byte/packet counts have been updated.
888class StreamDataCountersCallback {
889 public:
890 virtual ~StreamDataCountersCallback() {}
891
892 virtual void DataCountersUpdated(const StreamDataCounters& counters,
893 uint32_t ssrc) = 0;
894};
pbosda903ea2015-10-02 09:36:56895
896// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
897// RTCP mode is described by RFC 5506.
898enum class RtcpMode { kOff, kCompound, kReducedSize };
899
pbos1ba8d392016-05-02 03:18:34900enum NetworkState {
901 kNetworkUp,
902 kNetworkDown,
903};
904
niklase@google.com470e71d2011-07-07 08:21:25905} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10906
907#endif // WEBRTC_COMMON_TYPES_H_