blob: 2988bf9f41a6fb8763cb31342217e24b4fe8d879 [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
17#include <string>
pbos@webrtc.orge2a7a772014-03-19 08:43:5718#include <vector>
19
kwibergc1a5e1b2016-11-29 13:30:4020#include "webrtc/base/checks.h"
Erik Språngfafcfc02016-11-16 15:41:3021#include "webrtc/base/optional.h"
magjed78706f42016-09-08 10:24:5822#include "webrtc/common_video/rotation.h"
andrew@webrtc.org5cf83f42013-09-09 17:50:1023#include "webrtc/typedefs.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2324
25#if defined(_MSC_VER)
26// Disable "new behavior: elements of array will be default initialized"
27// warning. Affects OverUseDetectorOptions.
solenbergfaa58c62016-09-01 14:54:5328#pragma warning(disable : 4351)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2329#endif
30
kwiberg15b966d2016-09-29 00:42:0131#if defined(WEBRTC_EXPORT)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2332#define WEBRTC_DLLEXPORT _declspec(dllexport)
kwiberg15b966d2016-09-29 00:42:0133#elif defined(WEBRTC_DLL)
andrew@webrtc.orgb015cbe2012-10-22 18:19:2334#define WEBRTC_DLLEXPORT _declspec(dllimport)
35#else
36#define WEBRTC_DLLEXPORT
37#endif
38
39#ifndef NULL
40#define NULL 0
41#endif
42
Peter Boströmcd71dc62016-02-26 15:31:3743#define RTP_PAYLOAD_NAME_SIZE 32u
andrew@webrtc.orgb015cbe2012-10-22 18:19:2344
mallinath@webrtc.org18c29452014-03-21 00:41:2845#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.org5cf83f42013-09-09 17:50:1046// Compares two strings without regard to case.
47#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
48// Compares characters of two strings without regard to case.
49#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
50#else
51#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
52#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
53#endif
54
andrew@webrtc.orgb015cbe2012-10-22 18:19:2355namespace webrtc {
56
tommia6d985c2016-06-15 17:30:1457class RewindableStream {
58 public:
59 virtual ~RewindableStream() {}
60 virtual int Rewind() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2361};
62
tommia6d985c2016-06-15 17:30:1463class InStream : public RewindableStream {
64 public:
65 // Reads |len| bytes from file to |buf|. Returns the number of bytes read
66 // or -1 on error.
67 virtual int Read(void* buf, size_t len) = 0;
68};
69
70class OutStream : public RewindableStream {
71 public:
72 // Writes |len| bytes from |buf| to file. The actual writing may happen
73 // some time later. Call Flush() to force a write.
74 virtual bool Write(const void* buf, size_t len) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2375};
76
solenbergfaa58c62016-09-01 14:54:5377enum TraceModule {
78 kTraceUndefined = 0,
79 // not a module, triggered from the engine code
80 kTraceVoice = 0x0001,
81 // not a module, triggered from the engine code
82 kTraceVideo = 0x0002,
83 // not a module, triggered from the utility code
84 kTraceUtility = 0x0003,
85 kTraceRtpRtcp = 0x0004,
86 kTraceTransport = 0x0005,
87 kTraceSrtp = 0x0006,
88 kTraceAudioCoding = 0x0007,
89 kTraceAudioMixerServer = 0x0008,
90 kTraceAudioMixerClient = 0x0009,
91 kTraceFile = 0x000a,
92 kTraceAudioProcessing = 0x000b,
93 kTraceVideoCoding = 0x0010,
94 kTraceVideoMixer = 0x0011,
95 kTraceAudioDevice = 0x0012,
96 kTraceVideoRenderer = 0x0014,
97 kTraceVideoCapture = 0x0015,
98 kTraceRemoteBitrateEstimator = 0x0017,
andrew@webrtc.orgb015cbe2012-10-22 18:19:2399};
100
solenbergfaa58c62016-09-01 14:54:53101enum TraceLevel {
102 kTraceNone = 0x0000, // no trace
103 kTraceStateInfo = 0x0001,
104 kTraceWarning = 0x0002,
105 kTraceError = 0x0004,
106 kTraceCritical = 0x0008,
107 kTraceApiCall = 0x0010,
108 kTraceDefault = 0x00ff,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23109
solenbergfaa58c62016-09-01 14:54:53110 kTraceModuleCall = 0x0020,
111 kTraceMemory = 0x0100, // memory info
112 kTraceTimer = 0x0200, // timing info
113 kTraceStream = 0x0400, // "continuous" stream of data
andrew@webrtc.orgb015cbe2012-10-22 18:19:23114
solenbergfaa58c62016-09-01 14:54:53115 // used for debug purposes
116 kTraceDebug = 0x0800, // debug
117 kTraceInfo = 0x1000, // debug info
andrew@webrtc.orgb015cbe2012-10-22 18:19:23118
solenbergfaa58c62016-09-01 14:54:53119 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
120 kTraceTerseInfo = 0x2000,
andrew@webrtc.orgbc687c52012-11-20 07:34:45121
solenbergfaa58c62016-09-01 14:54:53122 kTraceAll = 0xffff
andrew@webrtc.orgb015cbe2012-10-22 18:19:23123};
124
125// External Trace API
andrew@webrtc.orgd75680a2012-11-15 05:33:25126class TraceCallback {
127 public:
128 virtual void Print(TraceLevel level, const char* message, int length) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23129
andrew@webrtc.orgd75680a2012-11-15 05:33:25130 protected:
131 virtual ~TraceCallback() {}
132 TraceCallback() {}
133};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23134
solenbergfaa58c62016-09-01 14:54:53135enum FileFormats {
136 kFileFormatWavFile = 1,
137 kFileFormatCompressedFile = 2,
138 kFileFormatPreencodedFile = 4,
139 kFileFormatPcm16kHzFile = 7,
140 kFileFormatPcm8kHzFile = 8,
141 kFileFormatPcm32kHzFile = 9
andrew@webrtc.orgb015cbe2012-10-22 18:19:23142};
143
solenbergfaa58c62016-09-01 14:54:53144enum ProcessingTypes {
145 kPlaybackPerChannel = 0,
146 kPlaybackAllChannelsMixed,
147 kRecordingPerChannel,
148 kRecordingAllChannelsMixed,
149 kRecordingPreprocessing
andrew@webrtc.orgb015cbe2012-10-22 18:19:23150};
151
pbosb63d8ad2015-10-19 09:39:06152enum FrameType {
153 kEmptyFrame = 0,
154 kAudioFrameSpeech = 1,
155 kAudioFrameCN = 2,
156 kVideoFrameKey = 3,
157 kVideoFrameDelta = 4,
sprang@webrtc.org5fdd10a2013-12-04 15:09:27158};
159
sprang@webrtc.org46736742013-11-20 16:47:07160// Statistics for an RTCP channel
sprang@webrtc.org2714c792013-10-28 09:21:07161struct RtcpStatistics {
sprang@webrtc.org2714c792013-10-28 09:21:07162 RtcpStatistics()
solenbergfaa58c62016-09-01 14:54:53163 : fraction_lost(0),
164 cumulative_lost(0),
165 extended_max_sequence_number(0),
166 jitter(0) {}
sprang@webrtc.org2714c792013-10-28 09:21:07167
168 uint8_t fraction_lost;
169 uint32_t cumulative_lost;
170 uint32_t extended_max_sequence_number;
171 uint32_t jitter;
sprang@webrtc.org2714c792013-10-28 09:21:07172};
173
sprang@webrtc.org46736742013-11-20 16:47:07174class RtcpStatisticsCallback {
175 public:
176 virtual ~RtcpStatisticsCallback() {}
177
178 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
179 uint32_t ssrc) = 0;
pbos@webrtc.org1a36f782014-12-18 13:50:16180 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07181};
182
asapersson@webrtc.org4a155602014-02-19 11:59:02183// Statistics for RTCP packet types.
184struct RtcpPacketTypeCounter {
185 RtcpPacketTypeCounter()
solenbergfaa58c62016-09-01 14:54:53186 : first_packet_time_ms(-1),
187 nack_packets(0),
188 fir_packets(0),
189 pli_packets(0),
190 nack_requests(0),
191 unique_nack_requests(0) {}
asapersson@webrtc.org4a155602014-02-19 11:59:02192
193 void Add(const RtcpPacketTypeCounter& other) {
194 nack_packets += other.nack_packets;
195 fir_packets += other.fir_packets;
196 pli_packets += other.pli_packets;
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30197 nack_requests += other.nack_requests;
198 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgc76c5532014-12-16 12:03:11199 if (other.first_packet_time_ms != -1 &&
solenbergfaa58c62016-09-01 14:54:53200 (other.first_packet_time_ms < first_packet_time_ms ||
201 first_packet_time_ms == -1)) {
asapersson@webrtc.orgc76c5532014-12-16 12:03:11202 // Use oldest time.
203 first_packet_time_ms = other.first_packet_time_ms;
204 }
205 }
206
sprang22c956d2016-02-24 15:55:00207 void Subtract(const RtcpPacketTypeCounter& other) {
208 nack_packets -= other.nack_packets;
209 fir_packets -= other.fir_packets;
210 pli_packets -= other.pli_packets;
211 nack_requests -= other.nack_requests;
212 unique_nack_requests -= other.unique_nack_requests;
213 if (other.first_packet_time_ms != -1 &&
214 (other.first_packet_time_ms > first_packet_time_ms ||
215 first_packet_time_ms == -1)) {
216 // Use youngest time.
217 first_packet_time_ms = other.first_packet_time_ms;
218 }
219 }
220
asapersson@webrtc.orgc76c5532014-12-16 12:03:11221 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
222 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org4a155602014-02-19 11:59:02223 }
224
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30225 int UniqueNackRequestsInPercent() const {
226 if (nack_requests == 0) {
227 return 0;
228 }
solenbergfaa58c62016-09-01 14:54:53229 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) +
230 0.5f);
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30231 }
232
solenbergfaa58c62016-09-01 14:54:53233 int64_t first_packet_time_ms; // Time when first packet is sent/received.
234 uint32_t nack_packets; // Number of RTCP NACK packets.
235 uint32_t fir_packets; // Number of RTCP FIR packets.
236 uint32_t pli_packets; // Number of RTCP PLI packets.
237 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30238 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org4a155602014-02-19 11:59:02239};
240
pbos@webrtc.orgeb1c2b52015-02-19 12:47:00241class RtcpPacketTypeCounterObserver {
242 public:
243 virtual ~RtcpPacketTypeCounterObserver() {}
244 virtual void RtcpPacketTypesCounterUpdated(
245 uint32_t ssrc,
246 const RtcpPacketTypeCounter& packet_counter) = 0;
247};
248
asapersson@webrtc.orgc76c5532014-12-16 12:03:11249// Rate statistics for a stream.
sprang@webrtc.org46736742013-11-20 16:47:07250struct BitrateStatistics {
sprang4c991f12016-07-13 16:11:28251 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.org46736742013-11-20 16:47:07252
solenbergfaa58c62016-09-01 14:54:53253 uint32_t bitrate_bps; // Bitrate in bits per second.
254 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.org46736742013-11-20 16:47:07255};
256
257// Callback, used to notify an observer whenever new rates have been estimated.
258class BitrateStatisticsObserver {
259 public:
260 virtual ~BitrateStatisticsObserver() {}
261
sprang4c991f12016-07-13 16:11:28262 virtual void Notify(uint32_t total_bitrate_bps,
263 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org52322672014-11-05 14:05:29264 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07265};
266
pbos@webrtc.org1a36f782014-12-18 13:50:16267struct FrameCounts {
268 FrameCounts() : key_frames(0), delta_frames(0) {}
269 int key_frames;
270 int delta_frames;
271};
272
asapersson@webrtc.orgc76c5532014-12-16 12:03:11273// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.org46736742013-11-20 16:47:07274class FrameCountObserver {
275 public:
sprang@webrtc.org21dc10d2013-11-21 09:09:54276 virtual ~FrameCountObserver() {}
pbos@webrtc.org1a36f782014-12-18 13:50:16277 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
278 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07279};
280
stefan@webrtc.org55b0f2e2014-07-11 13:44:02281// Callback, used to notify an observer whenever the send-side delay is updated.
282class SendSideDelayObserver {
283 public:
284 virtual ~SendSideDelayObserver() {}
285 virtual void SendSideDelayUpdated(int avg_delay_ms,
286 int max_delay_ms,
287 uint32_t ssrc) = 0;
288};
289
asapersson86a285e2016-05-03 06:44:01290// Callback, used to notify an observer whenever a packet is sent to the
291// transport.
292// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
293// Remove SendSideDelayObserver once possible.
294class SendPacketObserver {
295 public:
296 virtual ~SendPacketObserver() {}
297 virtual void OnSendPacket(uint16_t packet_id,
298 int64_t capture_time_ms,
299 uint32_t ssrc) = 0;
300};
301
michaelt57beae32016-11-17 09:38:43302// Callback, used to notify an observer when the overhead per packet
303// has changed.
304class OverheadObserver {
305 public:
306 virtual ~OverheadObserver() = default;
307 virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0;
308};
309
andrew@webrtc.orgb015cbe2012-10-22 18:19:23310// ==================================================================
311// Voice specific types
312// ==================================================================
313
314// Each codec supported can be described by this structure.
mallinath@webrtc.org18c29452014-03-21 00:41:28315struct CodecInst {
316 int pltype;
317 char plname[RTP_PAYLOAD_NAME_SIZE];
318 int plfreq;
319 int pacsize;
Peter Kasting80590d92016-01-13 00:26:35320 size_t channels;
mallinath@webrtc.org18c29452014-03-21 00:41:28321 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
322
323 bool operator==(const CodecInst& other) const {
324 return pltype == other.pltype &&
325 (STR_CASE_CMP(plname, other.plname) == 0) &&
solenbergfaa58c62016-09-01 14:54:53326 plfreq == other.plfreq && pacsize == other.pacsize &&
327 channels == other.channels && rate == other.rate;
mallinath@webrtc.org18c29452014-03-21 00:41:28328 }
329
solenbergfaa58c62016-09-01 14:54:53330 bool operator!=(const CodecInst& other) const { return !(*this == other); }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23331};
332
andrew@webrtc.orgb015cbe2012-10-22 18:19:23333// RTP
solenbergfaa58c62016-09-01 14:54:53334enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
andrew@webrtc.orgb015cbe2012-10-22 18:19:23335
solenbergfaa58c62016-09-01 14:54:53336enum PayloadFrequencies {
337 kFreq8000Hz = 8000,
338 kFreq16000Hz = 16000,
339 kFreq32000Hz = 32000
andrew@webrtc.orgb015cbe2012-10-22 18:19:23340};
341
solenbergfaa58c62016-09-01 14:54:53342// Degree of bandwidth reduction.
343enum VadModes {
344 kVadConventional = 0, // lowest reduction
345 kVadAggressiveLow,
346 kVadAggressiveMid,
347 kVadAggressiveHigh // highest reduction
andrew@webrtc.orgb015cbe2012-10-22 18:19:23348};
349
solenbergfaa58c62016-09-01 14:54:53350// NETEQ statistics.
351struct NetworkStatistics {
352 // current jitter buffer size in ms
353 uint16_t currentBufferSize;
354 // preferred (optimal) buffer size in ms
355 uint16_t preferredBufferSize;
356 // adding extra delay due to "peaky jitter"
357 bool jitterPeaksFound;
358 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
359 uint16_t currentPacketLossRate;
360 // Late loss rate; fraction between 0 and 1, scaled to Q14.
361 uint16_t currentDiscardRate;
362 // fraction (of original stream) of synthesized audio inserted through
363 // expansion (in Q14)
364 uint16_t currentExpandRate;
365 // fraction (of original stream) of synthesized speech inserted through
366 // expansion (in Q14)
367 uint16_t currentSpeechExpandRate;
368 // fraction of synthesized speech inserted through pre-emptive expansion
369 // (in Q14)
370 uint16_t currentPreemptiveRate;
371 // fraction of data removed through acceleration (in Q14)
372 uint16_t currentAccelerateRate;
373 // fraction of data coming from secondary decoding (in Q14)
374 uint16_t currentSecondaryDecodedRate;
375 // clock-drift in parts-per-million (negative or positive)
376 int32_t clockDriftPPM;
377 // average packet waiting time in the jitter buffer (ms)
378 int meanWaitingTimeMs;
379 // median packet waiting time in the jitter buffer (ms)
380 int medianWaitingTimeMs;
381 // min packet waiting time in the jitter buffer (ms)
382 int minWaitingTimeMs;
383 // max packet waiting time in the jitter buffer (ms)
384 int maxWaitingTimeMs;
385 // added samples in off mode due to packet loss
386 size_t addedSamples;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23387};
388
wu@webrtc.org79d6daf2013-12-13 19:17:43389// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
390struct AudioDecodingCallStats {
391 AudioDecodingCallStats()
392 : calls_to_silence_generator(0),
393 calls_to_neteq(0),
394 decoded_normal(0),
395 decoded_plc(0),
396 decoded_cng(0),
henrik.lundin4450c272016-09-20 08:47:12397 decoded_plc_cng(0),
398 decoded_muted_output(0) {}
wu@webrtc.org79d6daf2013-12-13 19:17:43399
400 int calls_to_silence_generator; // Number of calls where silence generated,
401 // and NetEq was disengaged from decoding.
solenbergfaa58c62016-09-01 14:54:53402 int calls_to_neteq; // Number of calls to NetEq.
wu@webrtc.org79d6daf2013-12-13 19:17:43403 int decoded_normal; // Number of calls where audio RTP packet decoded.
solenbergfaa58c62016-09-01 14:54:53404 int decoded_plc; // Number of calls resulted in PLC.
wu@webrtc.org79d6daf2013-12-13 19:17:43405 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
406 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
henrik.lundin4450c272016-09-20 08:47:12407 int decoded_muted_output; // Number of calls returning a muted state output.
wu@webrtc.org79d6daf2013-12-13 19:17:43408};
409
solenbergfaa58c62016-09-01 14:54:53410// Type of Noise Suppression.
411enum NsModes {
412 kNsUnchanged = 0, // previously set mode
413 kNsDefault, // platform default
414 kNsConference, // conferencing default
415 kNsLowSuppression, // lowest suppression
416 kNsModerateSuppression,
417 kNsHighSuppression,
418 kNsVeryHighSuppression, // highest suppression
andrew@webrtc.orgb015cbe2012-10-22 18:19:23419};
420
solenbergfaa58c62016-09-01 14:54:53421// Type of Automatic Gain Control.
422enum AgcModes {
423 kAgcUnchanged = 0, // previously set mode
424 kAgcDefault, // platform default
425 // adaptive mode for use when analog volume control exists (e.g. for
426 // PC softphone)
427 kAgcAdaptiveAnalog,
428 // scaling takes place in the digital domain (e.g. for conference servers
429 // and embedded devices)
430 kAgcAdaptiveDigital,
431 // can be used on embedded devices where the capture signal level
432 // is predictable
433 kAgcFixedDigital
andrew@webrtc.orgb015cbe2012-10-22 18:19:23434};
435
solenbergfaa58c62016-09-01 14:54:53436// Type of Echo Control.
437enum EcModes {
438 kEcUnchanged = 0, // previously set mode
439 kEcDefault, // platform default
440 kEcConference, // conferencing default (aggressive AEC)
441 kEcAec, // Acoustic Echo Cancellation
442 kEcAecm, // AEC mobile
andrew@webrtc.orgb015cbe2012-10-22 18:19:23443};
444
solenbergfaa58c62016-09-01 14:54:53445// Mode of AECM.
446enum AecmModes {
447 kAecmQuietEarpieceOrHeadset = 0,
448 // Quiet earpiece or headset use
449 kAecmEarpiece, // most earpiece use
450 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
451 kAecmSpeakerphone, // most speakerphone use (default)
452 kAecmLoudSpeakerphone // Loud speakerphone
andrew@webrtc.orgb015cbe2012-10-22 18:19:23453};
454
solenbergcb186502016-08-31 21:48:53455// AGC configuration parameters
solenbergfaa58c62016-09-01 14:54:53456struct AgcConfig {
457 unsigned short targetLeveldBOv;
458 unsigned short digitalCompressionGaindB;
459 bool limiterEnable;
solenbergcb186502016-08-31 21:48:53460};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23461
solenbergfaa58c62016-09-01 14:54:53462enum StereoChannel { kStereoLeft = 0, kStereoRight, kStereoBoth };
andrew@webrtc.orgb015cbe2012-10-22 18:19:23463
464// Audio device layers
solenbergfaa58c62016-09-01 14:54:53465enum AudioLayers {
466 kAudioPlatformDefault = 0,
467 kAudioWindowsWave = 1,
468 kAudioWindowsCore = 2,
469 kAudioLinuxAlsa = 3,
470 kAudioLinuxPulse = 4
andrew@webrtc.orgb015cbe2012-10-22 18:19:23471};
472
andrew@webrtc.orgb015cbe2012-10-22 18:19:23473// ==================================================================
474// Video specific types
475// ==================================================================
476
477// Raw video types
solenbergfaa58c62016-09-01 14:54:53478enum RawVideoType {
479 kVideoI420 = 0,
480 kVideoYV12 = 1,
481 kVideoYUY2 = 2,
482 kVideoUYVY = 3,
483 kVideoIYUV = 4,
484 kVideoARGB = 5,
485 kVideoRGB24 = 6,
486 kVideoRGB565 = 7,
487 kVideoARGB4444 = 8,
488 kVideoARGB1555 = 9,
489 kVideoMJPEG = 10,
490 kVideoNV12 = 11,
491 kVideoNV21 = 12,
492 kVideoBGRA = 13,
493 kVideoUnknown = 99
andrew@webrtc.orgb015cbe2012-10-22 18:19:23494};
495
496// Video codec
solenbergfaa58c62016-09-01 14:54:53497enum { kConfigParameterSize = 128 };
498enum { kPayloadNameSize = 32 };
499enum { kMaxSimulcastStreams = 4 };
sprang0ba16d12015-11-02 15:23:20500enum { kMaxSpatialLayers = 5 };
solenbergfaa58c62016-09-01 14:54:53501enum { kMaxTemporalStreams = 4 };
andrew@webrtc.orgb015cbe2012-10-22 18:19:23502
solenbergfaa58c62016-09-01 14:54:53503enum VideoCodecComplexity {
504 kComplexityNormal = 0,
505 kComplexityHigh = 1,
506 kComplexityHigher = 2,
507 kComplexityMax = 3
andrew@webrtc.orgb015cbe2012-10-22 18:19:23508};
509
andrew@webrtc.orgb015cbe2012-10-22 18:19:23510enum VP8ResilienceMode {
511 kResilienceOff, // The stream produced by the encoder requires a
512 // recovery frame (typically a key frame) to be
513 // decodable after a packet loss.
514 kResilientStream, // A stream produced by the encoder is resilient to
515 // packet losses, but packets within a frame subsequent
516 // to a loss can't be decoded.
517 kResilientFrames // Same as kResilientStream but with added resilience
518 // within a frame.
519};
520
Peter Boströmd1460022016-01-19 15:26:16521class TemporalLayersFactory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23522// VP8 specific
mallinath@webrtc.org18c29452014-03-21 00:41:28523struct VideoCodecVP8 {
solenbergfaa58c62016-09-01 14:54:53524 bool pictureLossIndicationOn;
525 bool feedbackModeOn;
mallinath@webrtc.org18c29452014-03-21 00:41:28526 VideoCodecComplexity complexity;
solenbergfaa58c62016-09-01 14:54:53527 VP8ResilienceMode resilience;
528 unsigned char numberOfTemporalLayers;
529 bool denoisingOn;
530 bool errorConcealmentOn;
531 bool automaticResizeOn;
532 bool frameDroppingOn;
533 int keyFrameInterval;
Erik Språngfafcfc02016-11-16 15:41:30534 TemporalLayersFactory* tl_factory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23535};
536
asapersson62407972015-07-31 13:10:09537// VP9 specific.
marpan@webrtc.org66373882014-11-01 06:10:48538struct VideoCodecVP9 {
539 VideoCodecComplexity complexity;
solenbergfaa58c62016-09-01 14:54:53540 int resilience;
541 unsigned char numberOfTemporalLayers;
542 bool denoisingOn;
543 bool frameDroppingOn;
544 int keyFrameInterval;
545 bool adaptiveQpMode;
546 bool automaticResizeOn;
547 unsigned char numberOfSpatialLayers;
548 bool flexibleMode;
marpan@webrtc.org66373882014-11-01 06:10:48549};
550
magjedb3b56b22016-11-25 18:06:31551// TODO(magjed): Move this and other H264 related classes out to their own file.
552namespace H264 {
553
554enum Profile {
555 kProfileConstrainedBaseline,
556 kProfileBaseline,
557 kProfileMain,
558 kProfileConstrainedHigh,
559 kProfileHigh,
560};
561
562} // namespace H264
563
stefan@webrtc.org2d4a80c2014-07-04 12:42:07564// H264 specific.
marpan@webrtc.org66373882014-11-01 06:10:48565struct VideoCodecH264 {
solenbergfaa58c62016-09-01 14:54:53566 bool frameDroppingOn;
567 int keyFrameInterval;
marpan@webrtc.org66373882014-11-01 06:10:48568 // These are NULL/0 if not externally negotiated.
569 const uint8_t* spsData;
solenbergfaa58c62016-09-01 14:54:53570 size_t spsLen;
marpan@webrtc.org66373882014-11-01 06:10:48571 const uint8_t* ppsData;
solenbergfaa58c62016-09-01 14:54:53572 size_t ppsLen;
magjedb3b56b22016-11-25 18:06:31573 H264::Profile profile;
stefan@webrtc.org2d4a80c2014-07-04 12:42:07574};
575
andrew@webrtc.orgb015cbe2012-10-22 18:19:23576// Video codec types
marpan@webrtc.org66373882014-11-01 06:10:48577enum VideoCodecType {
578 kVideoCodecVP8,
579 kVideoCodecVP9,
580 kVideoCodecH264,
581 kVideoCodecI420,
582 kVideoCodecRED,
583 kVideoCodecULPFEC,
brandtr8b00e9b2016-11-07 11:03:41584 kVideoCodecFlexfec,
marpan@webrtc.org66373882014-11-01 06:10:48585 kVideoCodecGeneric,
586 kVideoCodecUnknown
andrew@webrtc.orgb015cbe2012-10-22 18:19:23587};
588
Erik Språngfafcfc02016-11-16 15:41:30589// Translates from name of codec to codec type and vice versa.
magjed3fcf7852016-11-22 18:16:57590rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type);
Erik Språngfafcfc02016-11-16 15:41:30591rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name);
592
marpan@webrtc.org66373882014-11-01 06:10:48593union VideoCodecUnion {
solenbergfaa58c62016-09-01 14:54:53594 VideoCodecVP8 VP8;
595 VideoCodecVP9 VP9;
596 VideoCodecH264 H264;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23597};
598
andrew@webrtc.orgb015cbe2012-10-22 18:19:23599// Simulcast is when the same stream is encoded multiple times with different
600// settings such as resolution.
mallinath@webrtc.org18c29452014-03-21 00:41:28601struct SimulcastStream {
solenbergfaa58c62016-09-01 14:54:53602 unsigned short width;
603 unsigned short height;
604 unsigned char numberOfTemporalLayers;
605 unsigned int maxBitrate; // kilobits/sec.
606 unsigned int targetBitrate; // kilobits/sec.
607 unsigned int minBitrate; // kilobits/sec.
608 unsigned int qpMax; // minimum quality
andrew@webrtc.orgb015cbe2012-10-22 18:19:23609};
610
sprang0ba16d12015-11-02 15:23:20611struct SpatialLayer {
612 int scaling_factor_num;
613 int scaling_factor_den;
614 int target_bitrate_bps;
615 // TODO(ivica): Add max_quantizer and min_quantizer?
616};
617
solenbergfaa58c62016-09-01 14:54:53618enum VideoCodecMode { kRealtimeVideo, kScreensharing };
stefan@webrtc.orgf4d37882013-02-18 14:40:18619
andrew@webrtc.orgb015cbe2012-10-22 18:19:23620// Common video codec properties
hta078cd6c2016-10-25 16:05:06621class VideoCodec {
622 public:
623 VideoCodec();
624
625 // Public variables. TODO(hta): Make them private with accessors.
solenbergfaa58c62016-09-01 14:54:53626 VideoCodecType codecType;
627 char plName[kPayloadNameSize];
628 unsigned char plType;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23629
solenbergfaa58c62016-09-01 14:54:53630 unsigned short width;
631 unsigned short height;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23632
solenbergfaa58c62016-09-01 14:54:53633 unsigned int startBitrate; // kilobits/sec.
634 unsigned int maxBitrate; // kilobits/sec.
635 unsigned int minBitrate; // kilobits/sec.
636 unsigned int targetBitrate; // kilobits/sec.
pbos@webrtc.org3d6910c2014-03-24 12:36:52637
solenbergfaa58c62016-09-01 14:54:53638 unsigned char maxFramerate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23639
solenbergfaa58c62016-09-01 14:54:53640 unsigned int qpMax;
641 unsigned char numberOfSimulcastStreams;
642 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprang0ba16d12015-11-02 15:23:20643 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgf4d37882013-02-18 14:40:18644
solenbergfaa58c62016-09-01 14:54:53645 VideoCodecMode mode;
646 bool expect_encode_from_texture;
andresp@webrtc.orgee6f8a22013-05-14 08:02:25647
Peter Boströmd1460022016-01-19 15:26:16648 bool operator==(const VideoCodec& other) const = delete;
649 bool operator!=(const VideoCodec& other) const = delete;
hta078cd6c2016-10-25 16:05:06650
651 // Accessors for codec specific information.
652 // There is a const version of each that returns a reference,
653 // and a non-const version that returns a pointer, in order
654 // to allow modification of the parameters.
655 VideoCodecVP8* VP8();
656 const VideoCodecVP8& VP8() const;
657 VideoCodecVP9* VP9();
658 const VideoCodecVP9& VP9() const;
659 VideoCodecH264* H264();
660 const VideoCodecH264& H264() const;
661
hta8ee78142016-11-17 07:23:04662 private:
hta078cd6c2016-10-25 16:05:06663 // TODO(hta): Consider replacing the union with a pointer type.
664 // This will allow removing the VideoCodec* types from this file.
hta8ee78142016-11-17 07:23:04665 VideoCodecUnion codec_specific_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23666};
667
Erik Språngfafcfc02016-11-16 15:41:30668class BitrateAllocation {
669 public:
670 static const uint32_t kMaxBitrateBps;
671 BitrateAllocation();
672
673 bool SetBitrate(size_t spatial_index,
674 size_t temporal_index,
675 uint32_t bitrate_bps);
676
677 uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const;
678
679 // Get the sum of all the temporal layer for a specific spatial layer.
680 uint32_t GetSpatialLayerSum(size_t spatial_index) const;
681
682 uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates.
683 uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; }
684
685 inline bool operator==(const BitrateAllocation& other) const {
686 return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0;
687 }
688 inline bool operator!=(const BitrateAllocation& other) const {
689 return !(*this == other);
690 }
691
692 private:
693 uint32_t sum_;
694 uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams];
695};
696
stefan12764bc2015-11-27 09:02:31697// Bandwidth over-use detector options. These are used to drive
698// experimentation with bandwidth estimation parameters.
699// See modules/remote_bitrate_estimator/overuse_detector.h
700struct OverUseDetectorOptions {
701 OverUseDetectorOptions()
solenbergfaa58c62016-09-01 14:54:53702 : initial_slope(8.0 / 512.0),
stefan12764bc2015-11-27 09:02:31703 initial_offset(0),
704 initial_e(),
705 initial_process_noise(),
706 initial_avg_noise(0.0),
707 initial_var_noise(50) {
708 initial_e[0][0] = 100;
709 initial_e[1][1] = 1e-1;
710 initial_e[0][1] = initial_e[1][0] = 0;
711 initial_process_noise[0] = 1e-13;
stefan84d41a32016-03-10 13:13:21712 initial_process_noise[1] = 1e-3;
stefan12764bc2015-11-27 09:02:31713 }
714 double initial_slope;
715 double initial_offset;
716 double initial_e[2][2];
717 double initial_process_noise[2];
718 double initial_avg_noise;
719 double initial_var_noise;
720};
721
wu@webrtc.orgefeb8ce2013-12-13 00:21:03722// This structure will have the information about when packet is actually
723// received by socket.
724struct PacketTime {
henrike@webrtc.org93ae8212014-04-29 17:50:47725 PacketTime() : timestamp(-1), not_before(-1) {}
726 PacketTime(int64_t timestamp, int64_t not_before)
solenbergfaa58c62016-09-01 14:54:53727 : timestamp(timestamp), not_before(not_before) {}
wu@webrtc.orgefeb8ce2013-12-13 00:21:03728
henrike@webrtc.org93ae8212014-04-29 17:50:47729 int64_t timestamp; // Receive time after socket delivers the data.
730 int64_t not_before; // Earliest possible time the data could have arrived,
731 // indicating the potential error in the |timestamp|
732 // value,in case the system is busy.
733 // For example, the time of the last select() call.
734 // If unknown, this value will be set to zero.
wu@webrtc.orgefeb8ce2013-12-13 00:21:03735};
736
isheriff00cc0452016-06-08 07:24:21737// Minimum and maximum playout delay values from capture to render.
738// These are best effort values.
739//
740// A value < 0 indicates no change from previous valid value.
741//
742// min = max = 0 indicates that the receiver should try and render
743// frame as soon as possible.
744//
745// min = x, max = y indicates that the receiver is free to adapt
746// in the range (x, y) based on network jitter.
747//
748// Note: Given that this gets embedded in a union, it is up-to the owner to
749// initialize these values.
750struct PlayoutDelay {
751 int min_ms;
752 int max_ms;
753};
754
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25755struct RTPHeaderExtension {
sprang@webrtc.org25ec20f2015-03-17 14:33:12756 RTPHeaderExtension();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25757
758 bool hasTransmissionTimeOffset;
759 int32_t transmissionTimeOffset;
760 bool hasAbsoluteSendTime;
761 uint32_t absoluteSendTime;
sprang@webrtc.org25ec20f2015-03-17 14:33:12762 bool hasTransportSequenceNumber;
763 uint16_t transportSequenceNumber;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25764
765 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
766 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
767 bool hasAudioLevel;
Minyueda4c0f02015-08-10 13:08:36768 bool voiceActivity;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25769 uint8_t audioLevel;
guoweis@webrtc.org5f74fcf2015-03-04 22:55:15770
771 // For Coordination of Video Orientation. See
772 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
773 // ts_126114v120700p.pdf
774 bool hasVideoRotation;
magjed78706f42016-09-08 10:24:58775 VideoRotation videoRotation;
isheriff00cc0452016-06-08 07:24:21776
777 PlayoutDelay playout_delay = {-1, -1};
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25778};
779
780struct RTPHeader {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22781 RTPHeader();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25782
783 bool markerBit;
784 uint8_t payloadType;
785 uint16_t sequenceNumber;
786 uint32_t timestamp;
787 uint32_t ssrc;
788 uint8_t numCSRCs;
789 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org0ab923a2014-11-20 22:28:14790 size_t paddingLength;
791 size_t headerLength;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25792 int payload_type_frequency;
793 RTPHeaderExtension extension;
794};
795
asapersson@webrtc.org1a8794b2015-02-04 08:34:47796struct RtpPacketCounter {
797 RtpPacketCounter()
solenbergfaa58c62016-09-01 14:54:53798 : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
asapersson@webrtc.org1a8794b2015-02-04 08:34:47799
800 void Add(const RtpPacketCounter& other) {
801 header_bytes += other.header_bytes;
802 payload_bytes += other.payload_bytes;
803 padding_bytes += other.padding_bytes;
804 packets += other.packets;
805 }
806
Erik Språng01cff722016-03-01 08:40:42807 void Subtract(const RtpPacketCounter& other) {
kwibergc1a5e1b2016-11-29 13:30:40808 RTC_DCHECK_GE(header_bytes, other.header_bytes);
Erik Språng01cff722016-03-01 08:40:42809 header_bytes -= other.header_bytes;
kwibergc1a5e1b2016-11-29 13:30:40810 RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
Erik Språng01cff722016-03-01 08:40:42811 payload_bytes -= other.payload_bytes;
kwibergc1a5e1b2016-11-29 13:30:40812 RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
Erik Språng01cff722016-03-01 08:40:42813 padding_bytes -= other.padding_bytes;
kwibergc1a5e1b2016-11-29 13:30:40814 RTC_DCHECK_GE(packets, other.packets);
Erik Språng01cff722016-03-01 08:40:42815 packets -= other.packets;
816 }
817
asapersson@webrtc.org1a8794b2015-02-04 08:34:47818 void AddPacket(size_t packet_length, const RTPHeader& header) {
819 ++packets;
820 header_bytes += header.headerLength;
821 padding_bytes += header.paddingLength;
822 payload_bytes +=
823 packet_length - (header.headerLength + header.paddingLength);
824 }
825
826 size_t TotalBytes() const {
827 return header_bytes + payload_bytes + padding_bytes;
828 }
829
830 size_t header_bytes; // Number of bytes used by RTP headers.
831 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
832 size_t padding_bytes; // Number of padding bytes.
833 uint32_t packets; // Number of packets.
834};
835
836// Data usage statistics for a (rtp) stream.
837struct StreamDataCounters {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22838 StreamDataCounters();
asapersson@webrtc.org1a8794b2015-02-04 08:34:47839
840 void Add(const StreamDataCounters& other) {
841 transmitted.Add(other.transmitted);
842 retransmitted.Add(other.retransmitted);
843 fec.Add(other.fec);
844 if (other.first_packet_time_ms != -1 &&
solenbergfaa58c62016-09-01 14:54:53845 (other.first_packet_time_ms < first_packet_time_ms ||
846 first_packet_time_ms == -1)) {
asapersson@webrtc.org1a8794b2015-02-04 08:34:47847 // Use oldest time.
848 first_packet_time_ms = other.first_packet_time_ms;
849 }
850 }
851
Erik Språng01cff722016-03-01 08:40:42852 void Subtract(const StreamDataCounters& other) {
853 transmitted.Subtract(other.transmitted);
854 retransmitted.Subtract(other.retransmitted);
855 fec.Subtract(other.fec);
856 if (other.first_packet_time_ms != -1 &&
857 (other.first_packet_time_ms > first_packet_time_ms ||
858 first_packet_time_ms == -1)) {
859 // Use youngest time.
860 first_packet_time_ms = other.first_packet_time_ms;
861 }
862 }
863
asapersson@webrtc.org1a8794b2015-02-04 08:34:47864 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
865 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
866 }
867
868 // Returns the number of bytes corresponding to the actual media payload (i.e.
869 // RTP headers, padding, retransmissions and fec packets are excluded).
870 // Note this function does not have meaning for an RTX stream.
871 size_t MediaPayloadBytes() const {
872 return transmitted.payload_bytes - retransmitted.payload_bytes -
873 fec.payload_bytes;
874 }
875
solenbergfaa58c62016-09-01 14:54:53876 int64_t first_packet_time_ms; // Time when first packet is sent/received.
877 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
asapersson@webrtc.org1a8794b2015-02-04 08:34:47878 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
solenbergfaa58c62016-09-01 14:54:53879 RtpPacketCounter fec; // Number of redundancy packets/bytes.
asapersson@webrtc.org1a8794b2015-02-04 08:34:47880};
881
882// Callback, called whenever byte/packet counts have been updated.
883class StreamDataCountersCallback {
884 public:
885 virtual ~StreamDataCountersCallback() {}
886
887 virtual void DataCountersUpdated(const StreamDataCounters& counters,
888 uint32_t ssrc) = 0;
889};
pbosba01e952015-10-02 09:36:56890
891// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
892// RTCP mode is described by RFC 5506.
893enum class RtcpMode { kOff, kCompound, kReducedSize };
894
pbos47a40a32016-05-02 03:18:34895enum NetworkState {
896 kNetworkUp,
897 kNetworkDown,
898};
899
andrew@webrtc.orgb015cbe2012-10-22 18:19:23900} // namespace webrtc
andrew@webrtc.org5cf83f42013-09-09 17:50:10901
902#endif // WEBRTC_COMMON_TYPES_H_