blob: bb29af0bebe0775054d5ec41dfe8365bb8084f13 [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
Erik Språng01cff722016-03-01 08:40:4214#include <assert.h>
pbos@webrtc.orge2a7a772014-03-19 08:43:5715#include <stddef.h>
mallinath@webrtc.org18c29452014-03-21 00:41:2816#include <string.h>
pbos@webrtc.org7e686932014-05-15 09:35:0617
18#include <string>
pbos@webrtc.orge2a7a772014-03-19 08:43:5719#include <vector>
20
andrew@webrtc.org5cf83f42013-09-09 17:50:1021#include "webrtc/typedefs.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2322
23#if defined(_MSC_VER)
24// Disable "new behavior: elements of array will be default initialized"
25// warning. Affects OverUseDetectorOptions.
26#pragma warning(disable:4351)
27#endif
28
29#ifdef WEBRTC_EXPORT
30#define WEBRTC_DLLEXPORT _declspec(dllexport)
31#elif WEBRTC_DLL
32#define WEBRTC_DLLEXPORT _declspec(dllimport)
33#else
34#define WEBRTC_DLLEXPORT
35#endif
36
37#ifndef NULL
38#define NULL 0
39#endif
40
Peter Boströmcd71dc62016-02-26 15:31:3741#define RTP_PAYLOAD_NAME_SIZE 32u
andrew@webrtc.orgb015cbe2012-10-22 18:19:2342
mallinath@webrtc.org18c29452014-03-21 00:41:2843#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.org5cf83f42013-09-09 17:50:1044// Compares two strings without regard to case.
45#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
46// Compares characters of two strings without regard to case.
47#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
48#else
49#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
50#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
51#endif
52
andrew@webrtc.orgb015cbe2012-10-22 18:19:2353namespace webrtc {
54
andresp@webrtc.orgee6f8a22013-05-14 08:02:2555class Config;
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
77enum TraceModule
78{
pbos@webrtc.org46f72882013-12-16 12:24:4479 kTraceUndefined = 0,
andrew@webrtc.orgb015cbe2012-10-22 18:19:2380 // not a module, triggered from the engine code
pbos@webrtc.org46f72882013-12-16 12:24:4481 kTraceVoice = 0x0001,
andrew@webrtc.orgb015cbe2012-10-22 18:19:2382 // not a module, triggered from the engine code
pbos@webrtc.org46f72882013-12-16 12:24:4483 kTraceVideo = 0x0002,
andrew@webrtc.orgb015cbe2012-10-22 18:19:2384 // not a module, triggered from the utility code
pbos@webrtc.org46f72882013-12-16 12:24:4485 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,
pbos@webrtc.org46f72882013-12-16 12:24:4499 kTraceRemoteBitrateEstimator = 0x0017,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23100};
101
102enum TraceLevel
103{
104 kTraceNone = 0x0000, // no trace
105 kTraceStateInfo = 0x0001,
106 kTraceWarning = 0x0002,
107 kTraceError = 0x0004,
108 kTraceCritical = 0x0008,
109 kTraceApiCall = 0x0010,
110 kTraceDefault = 0x00ff,
111
112 kTraceModuleCall = 0x0020,
113 kTraceMemory = 0x0100, // memory info
114 kTraceTimer = 0x0200, // timing info
115 kTraceStream = 0x0400, // "continuous" stream of data
116
117 // used for debug purposes
118 kTraceDebug = 0x0800, // debug
119 kTraceInfo = 0x1000, // debug info
120
andrew@webrtc.orgbc687c52012-11-20 07:34:45121 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
122 kTraceTerseInfo = 0x2000,
123
andrew@webrtc.orgb015cbe2012-10-22 18:19:23124 kTraceAll = 0xffff
125};
126
127// External Trace API
andrew@webrtc.orgd75680a2012-11-15 05:33:25128class TraceCallback {
129 public:
130 virtual void Print(TraceLevel level, const char* message, int length) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23131
andrew@webrtc.orgd75680a2012-11-15 05:33:25132 protected:
133 virtual ~TraceCallback() {}
134 TraceCallback() {}
135};
andrew@webrtc.orgb015cbe2012-10-22 18:19:23136
137enum FileFormats
138{
139 kFileFormatWavFile = 1,
140 kFileFormatCompressedFile = 2,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23141 kFileFormatPreencodedFile = 4,
142 kFileFormatPcm16kHzFile = 7,
143 kFileFormatPcm8kHzFile = 8,
144 kFileFormatPcm32kHzFile = 9
145};
146
andrew@webrtc.orgb015cbe2012-10-22 18:19:23147enum ProcessingTypes
148{
149 kPlaybackPerChannel = 0,
150 kPlaybackAllChannelsMixed,
151 kRecordingPerChannel,
152 kRecordingAllChannelsMixed,
153 kRecordingPreprocessing
154};
155
pbosb63d8ad2015-10-19 09:39:06156enum FrameType {
157 kEmptyFrame = 0,
158 kAudioFrameSpeech = 1,
159 kAudioFrameCN = 2,
160 kVideoFrameKey = 3,
161 kVideoFrameDelta = 4,
sprang@webrtc.org5fdd10a2013-12-04 15:09:27162};
163
sprang@webrtc.org46736742013-11-20 16:47:07164// Statistics for an RTCP channel
sprang@webrtc.org2714c792013-10-28 09:21:07165struct RtcpStatistics {
sprang@webrtc.org2714c792013-10-28 09:21:07166 RtcpStatistics()
167 : fraction_lost(0),
168 cumulative_lost(0),
169 extended_max_sequence_number(0),
sprang@webrtc.org9b30fd32013-12-05 09:48:44170 jitter(0) {}
sprang@webrtc.org2714c792013-10-28 09:21:07171
172 uint8_t fraction_lost;
173 uint32_t cumulative_lost;
174 uint32_t extended_max_sequence_number;
175 uint32_t jitter;
sprang@webrtc.org2714c792013-10-28 09:21:07176};
177
sprang@webrtc.org46736742013-11-20 16:47:07178class RtcpStatisticsCallback {
179 public:
180 virtual ~RtcpStatisticsCallback() {}
181
182 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
183 uint32_t ssrc) = 0;
pbos@webrtc.org1a36f782014-12-18 13:50:16184 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07185};
186
asapersson@webrtc.org4a155602014-02-19 11:59:02187// Statistics for RTCP packet types.
188struct RtcpPacketTypeCounter {
189 RtcpPacketTypeCounter()
asapersson@webrtc.orgc76c5532014-12-16 12:03:11190 : first_packet_time_ms(-1),
191 nack_packets(0),
asapersson@webrtc.org4a155602014-02-19 11:59:02192 fir_packets(0),
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30193 pli_packets(0),
194 nack_requests(0),
195 unique_nack_requests(0) {}
asapersson@webrtc.org4a155602014-02-19 11:59:02196
197 void Add(const RtcpPacketTypeCounter& other) {
198 nack_packets += other.nack_packets;
199 fir_packets += other.fir_packets;
200 pli_packets += other.pli_packets;
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30201 nack_requests += other.nack_requests;
202 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgc76c5532014-12-16 12:03:11203 if (other.first_packet_time_ms != -1 &&
204 (other.first_packet_time_ms < first_packet_time_ms ||
205 first_packet_time_ms == -1)) {
206 // Use oldest time.
207 first_packet_time_ms = other.first_packet_time_ms;
208 }
209 }
210
sprang22c956d2016-02-24 15:55:00211 void Subtract(const RtcpPacketTypeCounter& other) {
212 nack_packets -= other.nack_packets;
213 fir_packets -= other.fir_packets;
214 pli_packets -= other.pli_packets;
215 nack_requests -= other.nack_requests;
216 unique_nack_requests -= other.unique_nack_requests;
217 if (other.first_packet_time_ms != -1 &&
218 (other.first_packet_time_ms > first_packet_time_ms ||
219 first_packet_time_ms == -1)) {
220 // Use youngest time.
221 first_packet_time_ms = other.first_packet_time_ms;
222 }
223 }
224
asapersson@webrtc.orgc76c5532014-12-16 12:03:11225 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
226 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
asapersson@webrtc.org4a155602014-02-19 11:59:02227 }
228
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30229 int UniqueNackRequestsInPercent() const {
230 if (nack_requests == 0) {
231 return 0;
232 }
233 return static_cast<int>(
234 (unique_nack_requests * 100.0f / nack_requests) + 0.5f);
235 }
236
asapersson@webrtc.orgc76c5532014-12-16 12:03:11237 int64_t first_packet_time_ms; // Time when first packet is sent/received.
238 uint32_t nack_packets; // Number of RTCP NACK packets.
239 uint32_t fir_packets; // Number of RTCP FIR packets.
240 uint32_t pli_packets; // Number of RTCP PLI packets.
241 uint32_t nack_requests; // Number of NACKed RTP packets.
asapersson@webrtc.org2ba45ee2014-10-29 12:42:30242 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org4a155602014-02-19 11:59:02243};
244
pbos@webrtc.orgeb1c2b52015-02-19 12:47:00245class RtcpPacketTypeCounterObserver {
246 public:
247 virtual ~RtcpPacketTypeCounterObserver() {}
248 virtual void RtcpPacketTypesCounterUpdated(
249 uint32_t ssrc,
250 const RtcpPacketTypeCounter& packet_counter) = 0;
251};
252
asapersson@webrtc.orgc76c5532014-12-16 12:03:11253// Rate statistics for a stream.
sprang@webrtc.org46736742013-11-20 16:47:07254struct BitrateStatistics {
sprang4c991f12016-07-13 16:11:28255 BitrateStatistics() : bitrate_bps(0), packet_rate(0) {}
sprang@webrtc.org46736742013-11-20 16:47:07256
sprang@webrtc.orgb70db6d2013-12-13 09:46:59257 uint32_t bitrate_bps; // Bitrate in bits per second.
258 uint32_t packet_rate; // Packet rate in packets per second.
sprang@webrtc.org46736742013-11-20 16:47:07259};
260
261// Callback, used to notify an observer whenever new rates have been estimated.
262class BitrateStatisticsObserver {
263 public:
264 virtual ~BitrateStatisticsObserver() {}
265
sprang4c991f12016-07-13 16:11:28266 virtual void Notify(uint32_t total_bitrate_bps,
267 uint32_t retransmit_bitrate_bps,
stefan@webrtc.org52322672014-11-05 14:05:29268 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07269};
270
pbos@webrtc.org1a36f782014-12-18 13:50:16271struct FrameCounts {
272 FrameCounts() : key_frames(0), delta_frames(0) {}
273 int key_frames;
274 int delta_frames;
275};
276
asapersson@webrtc.orgc76c5532014-12-16 12:03:11277// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.org46736742013-11-20 16:47:07278class FrameCountObserver {
279 public:
sprang@webrtc.org21dc10d2013-11-21 09:09:54280 virtual ~FrameCountObserver() {}
pbos@webrtc.org1a36f782014-12-18 13:50:16281 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
282 uint32_t ssrc) = 0;
sprang@webrtc.org46736742013-11-20 16:47:07283};
284
stefan@webrtc.org55b0f2e2014-07-11 13:44:02285// Callback, used to notify an observer whenever the send-side delay is updated.
286class SendSideDelayObserver {
287 public:
288 virtual ~SendSideDelayObserver() {}
289 virtual void SendSideDelayUpdated(int avg_delay_ms,
290 int max_delay_ms,
291 uint32_t ssrc) = 0;
292};
293
asapersson86a285e2016-05-03 06:44:01294// Callback, used to notify an observer whenever a packet is sent to the
295// transport.
296// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
297// Remove SendSideDelayObserver once possible.
298class SendPacketObserver {
299 public:
300 virtual ~SendPacketObserver() {}
301 virtual void OnSendPacket(uint16_t packet_id,
302 int64_t capture_time_ms,
303 uint32_t ssrc) = 0;
304};
305
andrew@webrtc.orgb015cbe2012-10-22 18:19:23306// ==================================================================
307// Voice specific types
308// ==================================================================
309
310// Each codec supported can be described by this structure.
mallinath@webrtc.org18c29452014-03-21 00:41:28311struct CodecInst {
312 int pltype;
313 char plname[RTP_PAYLOAD_NAME_SIZE];
314 int plfreq;
315 int pacsize;
Peter Kasting80590d92016-01-13 00:26:35316 size_t channels;
mallinath@webrtc.org18c29452014-03-21 00:41:28317 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
318
319 bool operator==(const CodecInst& other) const {
320 return pltype == other.pltype &&
321 (STR_CASE_CMP(plname, other.plname) == 0) &&
322 plfreq == other.plfreq &&
323 pacsize == other.pacsize &&
324 channels == other.channels &&
325 rate == other.rate;
326 }
327
328 bool operator!=(const CodecInst& other) const {
329 return !(*this == other);
330 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23331};
332
andrew@webrtc.orgb015cbe2012-10-22 18:19:23333// RTP
334enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
335
andrew@webrtc.orgb015cbe2012-10-22 18:19:23336enum PayloadFrequencies
337{
338 kFreq8000Hz = 8000,
339 kFreq16000Hz = 16000,
340 kFreq32000Hz = 32000
341};
342
343enum VadModes // degree of bandwidth reduction
344{
345 kVadConventional = 0, // lowest reduction
346 kVadAggressiveLow,
347 kVadAggressiveMid,
348 kVadAggressiveHigh // highest reduction
349};
350
351struct NetworkStatistics // NETEQ statistics
352{
353 // current jitter buffer size in ms
pbos@webrtc.org52b2ee52013-05-03 12:02:11354 uint16_t currentBufferSize;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23355 // preferred (optimal) buffer size in ms
pbos@webrtc.org52b2ee52013-05-03 12:02:11356 uint16_t preferredBufferSize;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23357 // adding extra delay due to "peaky jitter"
358 bool jitterPeaksFound;
henrik.lundin@webrtc.org6e7480a2014-10-09 12:58:45359 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
pbos@webrtc.org52b2ee52013-05-03 12:02:11360 uint16_t currentPacketLossRate;
henrik.lundin@webrtc.org6e7480a2014-10-09 12:58:45361 // Late loss rate; fraction between 0 and 1, scaled to Q14.
pbos@webrtc.org52b2ee52013-05-03 12:02:11362 uint16_t currentDiscardRate;
minyue@webrtc.org5f8d2882015-02-18 15:24:13363 // fraction (of original stream) of synthesized audio inserted through
andrew@webrtc.orgb015cbe2012-10-22 18:19:23364 // expansion (in Q14)
pbos@webrtc.org52b2ee52013-05-03 12:02:11365 uint16_t currentExpandRate;
minyue@webrtc.org5f8d2882015-02-18 15:24:13366 // fraction (of original stream) of synthesized speech inserted through
367 // expansion (in Q14)
368 uint16_t currentSpeechExpandRate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23369 // fraction of synthesized speech inserted through pre-emptive expansion
370 // (in Q14)
pbos@webrtc.org52b2ee52013-05-03 12:02:11371 uint16_t currentPreemptiveRate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23372 // fraction of data removed through acceleration (in Q14)
pbos@webrtc.org52b2ee52013-05-03 12:02:11373 uint16_t currentAccelerateRate;
minyue@webrtc.org5f8d2882015-02-18 15:24:13374 // fraction of data coming from secondary decoding (in Q14)
375 uint16_t currentSecondaryDecodedRate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23376 // clock-drift in parts-per-million (negative or positive)
377 int32_t clockDriftPPM;
378 // average packet waiting time in the jitter buffer (ms)
379 int meanWaitingTimeMs;
380 // median packet waiting time in the jitter buffer (ms)
381 int medianWaitingTimeMs;
382 // min packet waiting time in the jitter buffer (ms)
383 int minWaitingTimeMs;
384 // max packet waiting time in the jitter buffer (ms)
385 int maxWaitingTimeMs;
roosa@google.com0049a762012-12-14 00:06:18386 // added samples in off mode due to packet loss
Peter Kastinga0ad2482015-08-24 21:52:23387 size_t addedSamples;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23388};
389
wu@webrtc.org79d6daf2013-12-13 19:17:43390// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
391struct AudioDecodingCallStats {
392 AudioDecodingCallStats()
393 : calls_to_silence_generator(0),
394 calls_to_neteq(0),
395 decoded_normal(0),
396 decoded_plc(0),
397 decoded_cng(0),
398 decoded_plc_cng(0) {}
399
400 int calls_to_silence_generator; // Number of calls where silence generated,
401 // and NetEq was disengaged from decoding.
402 int calls_to_neteq; // Number of calls to NetEq.
403 int decoded_normal; // Number of calls where audio RTP packet decoded.
404 int decoded_plc; // Number of calls resulted in PLC.
405 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.
407};
408
andrew@webrtc.orgb015cbe2012-10-22 18:19:23409typedef struct
410{
411 int min; // minumum
412 int max; // maximum
413 int average; // average
414} StatVal;
415
416typedef struct // All levels are reported in dBm0
417{
418 StatVal speech_rx; // long-term speech levels on receiving side
419 StatVal speech_tx; // long-term speech levels on transmitting side
420 StatVal noise_rx; // long-term noise/silence levels on receiving side
421 StatVal noise_tx; // long-term noise/silence levels on transmitting side
422} LevelStatistics;
423
424typedef struct // All levels are reported in dB
425{
426 StatVal erl; // Echo Return Loss
427 StatVal erle; // Echo Return Loss Enhancement
428 StatVal rerl; // RERL = ERL + ERLE
429 // Echo suppression inside EC at the point just before its NLP
430 StatVal a_nlp;
431} EchoStatistics;
432
andrew@webrtc.orgb015cbe2012-10-22 18:19:23433enum NsModes // type of Noise Suppression
434{
435 kNsUnchanged = 0, // previously set mode
436 kNsDefault, // platform default
437 kNsConference, // conferencing default
438 kNsLowSuppression, // lowest suppression
439 kNsModerateSuppression,
440 kNsHighSuppression,
441 kNsVeryHighSuppression, // highest suppression
442};
443
444enum AgcModes // type of Automatic Gain Control
445{
446 kAgcUnchanged = 0, // previously set mode
447 kAgcDefault, // platform default
448 // adaptive mode for use when analog volume control exists (e.g. for
449 // PC softphone)
450 kAgcAdaptiveAnalog,
451 // scaling takes place in the digital domain (e.g. for conference servers
452 // and embedded devices)
453 kAgcAdaptiveDigital,
454 // can be used on embedded devices where the capture signal level
455 // is predictable
456 kAgcFixedDigital
457};
458
459// EC modes
460enum EcModes // type of Echo Control
461{
462 kEcUnchanged = 0, // previously set mode
463 kEcDefault, // platform default
464 kEcConference, // conferencing default (aggressive AEC)
465 kEcAec, // Acoustic Echo Cancellation
466 kEcAecm, // AEC mobile
467};
468
469// AECM modes
470enum AecmModes // mode of AECM
471{
472 kAecmQuietEarpieceOrHeadset = 0,
473 // Quiet earpiece or headset use
474 kAecmEarpiece, // most earpiece use
475 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
476 kAecmSpeakerphone, // most speakerphone use (default)
477 kAecmLoudSpeakerphone // Loud speakerphone
478};
479
480// AGC configuration
481typedef struct
482{
483 unsigned short targetLeveldBOv;
484 unsigned short digitalCompressionGaindB;
485 bool limiterEnable;
486} AgcConfig; // AGC configuration parameters
487
488enum StereoChannel
489{
490 kStereoLeft = 0,
491 kStereoRight,
492 kStereoBoth
493};
494
495// Audio device layers
496enum AudioLayers
497{
498 kAudioPlatformDefault = 0,
499 kAudioWindowsWave = 1,
500 kAudioWindowsCore = 2,
501 kAudioLinuxAlsa = 3,
502 kAudioLinuxPulse = 4
503};
504
henrika@webrtc.org692224a2014-04-17 10:45:01505// TODO(henrika): to be removed.
andrew@webrtc.orgb015cbe2012-10-22 18:19:23506enum NetEqModes // NetEQ playout configurations
507{
508 // Optimized trade-off between low delay and jitter robustness for two-way
509 // communication.
510 kNetEqDefault = 0,
511 // Improved jitter robustness at the cost of increased delay. Can be
512 // used in one-way communication.
513 kNetEqStreaming = 1,
514 // Optimzed for decodability of fax signals rather than for perceived audio
515 // quality.
516 kNetEqFax = 2,
roosa@google.com90d333e2012-12-12 21:59:14517 // Minimal buffer management. Inserts zeros for lost packets and during
518 // buffer increases.
519 kNetEqOff = 3,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23520};
521
henrika@webrtc.org692224a2014-04-17 10:45:01522// TODO(henrika): to be removed.
andrew@webrtc.orgb015cbe2012-10-22 18:19:23523enum OnHoldModes // On Hold direction
524{
525 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
526 kHoldSendOnly, // Put only sending in on-hold state.
527 kHoldPlayOnly // Put only playing in on-hold state.
528};
529
henrika@webrtc.org692224a2014-04-17 10:45:01530// TODO(henrika): to be removed.
andrew@webrtc.orgb015cbe2012-10-22 18:19:23531enum AmrMode
532{
533 kRfc3267BwEfficient = 0,
534 kRfc3267OctetAligned = 1,
535 kRfc3267FileStorage = 2,
536};
537
538// ==================================================================
539// Video specific types
540// ==================================================================
541
542// Raw video types
543enum RawVideoType
544{
545 kVideoI420 = 0,
546 kVideoYV12 = 1,
547 kVideoYUY2 = 2,
548 kVideoUYVY = 3,
549 kVideoIYUV = 4,
550 kVideoARGB = 5,
551 kVideoRGB24 = 6,
552 kVideoRGB565 = 7,
553 kVideoARGB4444 = 8,
554 kVideoARGB1555 = 9,
555 kVideoMJPEG = 10,
556 kVideoNV12 = 11,
557 kVideoNV21 = 12,
558 kVideoBGRA = 13,
559 kVideoUnknown = 99
560};
561
562// Video codec
563enum { kConfigParameterSize = 128};
564enum { kPayloadNameSize = 32};
565enum { kMaxSimulcastStreams = 4};
sprang0ba16d12015-11-02 15:23:20566enum { kMaxSpatialLayers = 5 };
andrew@webrtc.orgb015cbe2012-10-22 18:19:23567enum { kMaxTemporalStreams = 4};
568
569enum VideoCodecComplexity
570{
571 kComplexityNormal = 0,
572 kComplexityHigh = 1,
573 kComplexityHigher = 2,
574 kComplexityMax = 3
575};
576
577enum VideoCodecProfile
578{
579 kProfileBase = 0x00,
580 kProfileMain = 0x01
581};
582
583enum VP8ResilienceMode {
584 kResilienceOff, // The stream produced by the encoder requires a
585 // recovery frame (typically a key frame) to be
586 // decodable after a packet loss.
587 kResilientStream, // A stream produced by the encoder is resilient to
588 // packet losses, but packets within a frame subsequent
589 // to a loss can't be decoded.
590 kResilientFrames // Same as kResilientStream but with added resilience
591 // within a frame.
592};
593
Peter Boströmd1460022016-01-19 15:26:16594class TemporalLayersFactory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23595// VP8 specific
mallinath@webrtc.org18c29452014-03-21 00:41:28596struct VideoCodecVP8 {
597 bool pictureLossIndicationOn;
598 bool feedbackModeOn;
599 VideoCodecComplexity complexity;
600 VP8ResilienceMode resilience;
601 unsigned char numberOfTemporalLayers;
602 bool denoisingOn;
603 bool errorConcealmentOn;
604 bool automaticResizeOn;
605 bool frameDroppingOn;
606 int keyFrameInterval;
Peter Boströmd1460022016-01-19 15:26:16607 const TemporalLayersFactory* tl_factory;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23608};
609
asapersson62407972015-07-31 13:10:09610// VP9 specific.
marpan@webrtc.org66373882014-11-01 06:10:48611struct VideoCodecVP9 {
612 VideoCodecComplexity complexity;
613 int resilience;
614 unsigned char numberOfTemporalLayers;
615 bool denoisingOn;
616 bool frameDroppingOn;
617 int keyFrameInterval;
618 bool adaptiveQpMode;
Marcoe8b7e112015-09-17 19:16:04619 bool automaticResizeOn;
asapersson62407972015-07-31 13:10:09620 unsigned char numberOfSpatialLayers;
621 bool flexibleMode;
marpan@webrtc.org66373882014-11-01 06:10:48622};
623
stefan@webrtc.org2d4a80c2014-07-04 12:42:07624// H264 specific.
marpan@webrtc.org66373882014-11-01 06:10:48625struct VideoCodecH264 {
626 VideoCodecProfile profile;
627 bool frameDroppingOn;
628 int keyFrameInterval;
629 // These are NULL/0 if not externally negotiated.
630 const uint8_t* spsData;
631 size_t spsLen;
632 const uint8_t* ppsData;
633 size_t ppsLen;
stefan@webrtc.org2d4a80c2014-07-04 12:42:07634};
635
andrew@webrtc.orgb015cbe2012-10-22 18:19:23636// Video codec types
marpan@webrtc.org66373882014-11-01 06:10:48637enum VideoCodecType {
638 kVideoCodecVP8,
639 kVideoCodecVP9,
640 kVideoCodecH264,
641 kVideoCodecI420,
642 kVideoCodecRED,
643 kVideoCodecULPFEC,
644 kVideoCodecGeneric,
645 kVideoCodecUnknown
andrew@webrtc.orgb015cbe2012-10-22 18:19:23646};
647
marpan@webrtc.org66373882014-11-01 06:10:48648union VideoCodecUnion {
649 VideoCodecVP8 VP8;
650 VideoCodecVP9 VP9;
651 VideoCodecH264 H264;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23652};
653
654
655// Simulcast is when the same stream is encoded multiple times with different
656// settings such as resolution.
mallinath@webrtc.org18c29452014-03-21 00:41:28657struct SimulcastStream {
658 unsigned short width;
659 unsigned short height;
660 unsigned char numberOfTemporalLayers;
661 unsigned int maxBitrate; // kilobits/sec.
662 unsigned int targetBitrate; // kilobits/sec.
663 unsigned int minBitrate; // kilobits/sec.
664 unsigned int qpMax; // minimum quality
andrew@webrtc.orgb015cbe2012-10-22 18:19:23665};
666
sprang0ba16d12015-11-02 15:23:20667struct SpatialLayer {
668 int scaling_factor_num;
669 int scaling_factor_den;
670 int target_bitrate_bps;
671 // TODO(ivica): Add max_quantizer and min_quantizer?
672};
673
stefan@webrtc.orgf4d37882013-02-18 14:40:18674enum VideoCodecMode {
675 kRealtimeVideo,
676 kScreensharing
677};
678
andrew@webrtc.orgb015cbe2012-10-22 18:19:23679// Common video codec properties
mallinath@webrtc.org18c29452014-03-21 00:41:28680struct VideoCodec {
681 VideoCodecType codecType;
682 char plName[kPayloadNameSize];
683 unsigned char plType;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23684
mallinath@webrtc.org18c29452014-03-21 00:41:28685 unsigned short width;
686 unsigned short height;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23687
mallinath@webrtc.org18c29452014-03-21 00:41:28688 unsigned int startBitrate; // kilobits/sec.
689 unsigned int maxBitrate; // kilobits/sec.
690 unsigned int minBitrate; // kilobits/sec.
pbos@webrtc.org3d6910c2014-03-24 12:36:52691 unsigned int targetBitrate; // kilobits/sec.
692
mallinath@webrtc.org18c29452014-03-21 00:41:28693 unsigned char maxFramerate;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23694
mallinath@webrtc.org18c29452014-03-21 00:41:28695 VideoCodecUnion codecSpecific;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23696
mallinath@webrtc.org18c29452014-03-21 00:41:28697 unsigned int qpMax;
698 unsigned char numberOfSimulcastStreams;
699 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprang0ba16d12015-11-02 15:23:20700 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgf4d37882013-02-18 14:40:18701
mallinath@webrtc.org18c29452014-03-21 00:41:28702 VideoCodecMode mode;
skvlad48be0542016-06-16 19:08:03703 bool expect_encode_from_texture;
andresp@webrtc.orgee6f8a22013-05-14 08:02:25704
Peter Boströmd1460022016-01-19 15:26:16705 bool operator==(const VideoCodec& other) const = delete;
706 bool operator!=(const VideoCodec& other) const = delete;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23707};
708
stefan12764bc2015-11-27 09:02:31709// Bandwidth over-use detector options. These are used to drive
710// experimentation with bandwidth estimation parameters.
711// See modules/remote_bitrate_estimator/overuse_detector.h
712struct OverUseDetectorOptions {
713 OverUseDetectorOptions()
714 : initial_slope(8.0/512.0),
715 initial_offset(0),
716 initial_e(),
717 initial_process_noise(),
718 initial_avg_noise(0.0),
719 initial_var_noise(50) {
720 initial_e[0][0] = 100;
721 initial_e[1][1] = 1e-1;
722 initial_e[0][1] = initial_e[1][0] = 0;
723 initial_process_noise[0] = 1e-13;
stefan84d41a32016-03-10 13:13:21724 initial_process_noise[1] = 1e-3;
stefan12764bc2015-11-27 09:02:31725 }
726 double initial_slope;
727 double initial_offset;
728 double initial_e[2][2];
729 double initial_process_noise[2];
730 double initial_avg_noise;
731 double initial_var_noise;
732};
733
wu@webrtc.orgefeb8ce2013-12-13 00:21:03734// This structure will have the information about when packet is actually
735// received by socket.
736struct PacketTime {
henrike@webrtc.org93ae8212014-04-29 17:50:47737 PacketTime() : timestamp(-1), not_before(-1) {}
738 PacketTime(int64_t timestamp, int64_t not_before)
739 : timestamp(timestamp), not_before(not_before) {
wu@webrtc.orgefeb8ce2013-12-13 00:21:03740 }
741
henrike@webrtc.org93ae8212014-04-29 17:50:47742 int64_t timestamp; // Receive time after socket delivers the data.
743 int64_t not_before; // Earliest possible time the data could have arrived,
744 // indicating the potential error in the |timestamp|
745 // value,in case the system is busy.
746 // For example, the time of the last select() call.
747 // If unknown, this value will be set to zero.
wu@webrtc.orgefeb8ce2013-12-13 00:21:03748};
749
isheriff00cc0452016-06-08 07:24:21750// Minimum and maximum playout delay values from capture to render.
751// These are best effort values.
752//
753// A value < 0 indicates no change from previous valid value.
754//
755// min = max = 0 indicates that the receiver should try and render
756// frame as soon as possible.
757//
758// min = x, max = y indicates that the receiver is free to adapt
759// in the range (x, y) based on network jitter.
760//
761// Note: Given that this gets embedded in a union, it is up-to the owner to
762// initialize these values.
763struct PlayoutDelay {
764 int min_ms;
765 int max_ms;
766};
767
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25768struct RTPHeaderExtension {
sprang@webrtc.org25ec20f2015-03-17 14:33:12769 RTPHeaderExtension();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25770
771 bool hasTransmissionTimeOffset;
772 int32_t transmissionTimeOffset;
773 bool hasAbsoluteSendTime;
774 uint32_t absoluteSendTime;
sprang@webrtc.org25ec20f2015-03-17 14:33:12775 bool hasTransportSequenceNumber;
776 uint16_t transportSequenceNumber;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25777
778 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
779 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
780 bool hasAudioLevel;
Minyueda4c0f02015-08-10 13:08:36781 bool voiceActivity;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25782 uint8_t audioLevel;
guoweis@webrtc.org5f74fcf2015-03-04 22:55:15783
784 // For Coordination of Video Orientation. See
785 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
786 // ts_126114v120700p.pdf
787 bool hasVideoRotation;
788 uint8_t videoRotation;
isheriff00cc0452016-06-08 07:24:21789
790 PlayoutDelay playout_delay = {-1, -1};
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25791};
792
793struct RTPHeader {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22794 RTPHeader();
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25795
796 bool markerBit;
797 uint8_t payloadType;
798 uint16_t sequenceNumber;
799 uint32_t timestamp;
800 uint32_t ssrc;
801 uint8_t numCSRCs;
802 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org0ab923a2014-11-20 22:28:14803 size_t paddingLength;
804 size_t headerLength;
solenberg@webrtc.orgfec6b6e2014-03-24 10:38:25805 int payload_type_frequency;
806 RTPHeaderExtension extension;
807};
808
asapersson@webrtc.org1a8794b2015-02-04 08:34:47809struct RtpPacketCounter {
810 RtpPacketCounter()
811 : header_bytes(0),
812 payload_bytes(0),
813 padding_bytes(0),
814 packets(0) {}
815
816 void Add(const RtpPacketCounter& other) {
817 header_bytes += other.header_bytes;
818 payload_bytes += other.payload_bytes;
819 padding_bytes += other.padding_bytes;
820 packets += other.packets;
821 }
822
Erik Språng01cff722016-03-01 08:40:42823 void Subtract(const RtpPacketCounter& other) {
824 assert(header_bytes >= other.header_bytes);
825 header_bytes -= other.header_bytes;
826 assert(payload_bytes >= other.payload_bytes);
827 payload_bytes -= other.payload_bytes;
828 assert(padding_bytes >= other.padding_bytes);
829 padding_bytes -= other.padding_bytes;
830 assert(packets >= other.packets);
831 packets -= other.packets;
832 }
833
asapersson@webrtc.org1a8794b2015-02-04 08:34:47834 void AddPacket(size_t packet_length, const RTPHeader& header) {
835 ++packets;
836 header_bytes += header.headerLength;
837 padding_bytes += header.paddingLength;
838 payload_bytes +=
839 packet_length - (header.headerLength + header.paddingLength);
840 }
841
842 size_t TotalBytes() const {
843 return header_bytes + payload_bytes + padding_bytes;
844 }
845
846 size_t header_bytes; // Number of bytes used by RTP headers.
847 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
848 size_t padding_bytes; // Number of padding bytes.
849 uint32_t packets; // Number of packets.
850};
851
852// Data usage statistics for a (rtp) stream.
853struct StreamDataCounters {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22854 StreamDataCounters();
asapersson@webrtc.org1a8794b2015-02-04 08:34:47855
856 void Add(const StreamDataCounters& other) {
857 transmitted.Add(other.transmitted);
858 retransmitted.Add(other.retransmitted);
859 fec.Add(other.fec);
860 if (other.first_packet_time_ms != -1 &&
861 (other.first_packet_time_ms < first_packet_time_ms ||
862 first_packet_time_ms == -1)) {
863 // Use oldest time.
864 first_packet_time_ms = other.first_packet_time_ms;
865 }
866 }
867
Erik Språng01cff722016-03-01 08:40:42868 void Subtract(const StreamDataCounters& other) {
869 transmitted.Subtract(other.transmitted);
870 retransmitted.Subtract(other.retransmitted);
871 fec.Subtract(other.fec);
872 if (other.first_packet_time_ms != -1 &&
873 (other.first_packet_time_ms > first_packet_time_ms ||
874 first_packet_time_ms == -1)) {
875 // Use youngest time.
876 first_packet_time_ms = other.first_packet_time_ms;
877 }
878 }
879
asapersson@webrtc.org1a8794b2015-02-04 08:34:47880 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
881 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
882 }
883
884 // Returns the number of bytes corresponding to the actual media payload (i.e.
885 // RTP headers, padding, retransmissions and fec packets are excluded).
886 // Note this function does not have meaning for an RTX stream.
887 size_t MediaPayloadBytes() const {
888 return transmitted.payload_bytes - retransmitted.payload_bytes -
889 fec.payload_bytes;
890 }
891
892 int64_t first_packet_time_ms; // Time when first packet is sent/received.
893 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
894 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
895 RtpPacketCounter fec; // Number of redundancy packets/bytes.
896};
897
898// Callback, called whenever byte/packet counts have been updated.
899class StreamDataCountersCallback {
900 public:
901 virtual ~StreamDataCountersCallback() {}
902
903 virtual void DataCountersUpdated(const StreamDataCounters& counters,
904 uint32_t ssrc) = 0;
905};
pbosba01e952015-10-02 09:36:56906
907// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
908// RTCP mode is described by RFC 5506.
909enum class RtcpMode { kOff, kCompound, kReducedSize };
910
pbos47a40a32016-05-02 03:18:34911enum NetworkState {
912 kNetworkUp,
913 kNetworkDown,
914};
915
andrew@webrtc.orgb015cbe2012-10-22 18:19:23916} // namespace webrtc
andrew@webrtc.org5cf83f42013-09-09 17:50:10917
918#endif // WEBRTC_COMMON_TYPES_H_