blob: 048485fa2fc89f99483230cb2f0b5f479acb7ed0 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
phoglund@webrtc.org8bfee842012-02-17 09:32:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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:10 +000011#ifndef WEBRTC_COMMON_TYPES_H_
12#define WEBRTC_COMMON_TYPES_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000014#include <stddef.h>
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000015#include <string.h>
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000016
17#include <string>
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000018#include <vector>
19
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +000020#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000022#if defined(_MSC_VER)
23// Disable "new behavior: elements of array will be default initialized"
24// warning. Affects OverUseDetectorOptions.
25#pragma warning(disable:4351)
26#endif
27
niklase@google.com470e71d2011-07-07 08:21:25 +000028#ifdef WEBRTC_EXPORT
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000029#define WEBRTC_DLLEXPORT _declspec(dllexport)
niklase@google.com470e71d2011-07-07 08:21:25 +000030#elif WEBRTC_DLL
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000031#define WEBRTC_DLLEXPORT _declspec(dllimport)
niklase@google.com470e71d2011-07-07 08:21:25 +000032#else
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000033#define WEBRTC_DLLEXPORT
niklase@google.com470e71d2011-07-07 08:21:25 +000034#endif
35
36#ifndef NULL
andrew@webrtc.org88b8b0d2012-08-14 00:05:56 +000037#define NULL 0
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39
henrika@webrtc.orgf75901f2012-01-16 08:45:42 +000040#define RTP_PAYLOAD_NAME_SIZE 32
41
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000042#if defined(WEBRTC_WIN) || defined(WIN32)
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +000043// Compares two strings without regard to case.
44#define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2)
45// Compares characters of two strings without regard to case.
46#define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n)
47#else
48#define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2)
49#define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n)
50#endif
51
niklase@google.com470e71d2011-07-07 08:21:25 +000052namespace webrtc {
53
andresp@webrtc.org185bae42013-05-14 08:02:25 +000054class Config;
55
niklase@google.com470e71d2011-07-07 08:21:25 +000056class InStream
57{
58public:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 // Reads |length| bytes from file to |buf|. Returns the number of bytes read
60 // or -1 on error.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000061 virtual int Read(void *buf, size_t len) = 0;
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000062 virtual int Rewind();
niklase@google.com470e71d2011-07-07 08:21:25 +000063 virtual ~InStream() {}
64protected:
65 InStream() {}
66};
67
68class OutStream
69{
70public:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000071 // Writes |length| bytes from |buf| to file. The actual writing may happen
72 // some time later. Call Flush() to force a write.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000073 virtual bool Write(const void *buf, size_t len) = 0;
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000074 virtual int Rewind();
niklase@google.com470e71d2011-07-07 08:21:25 +000075 virtual ~OutStream() {}
76protected:
77 OutStream() {}
78};
79
80enum TraceModule
81{
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000082 kTraceUndefined = 0,
niklase@google.com470e71d2011-07-07 08:21:25 +000083 // not a module, triggered from the engine code
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000084 kTraceVoice = 0x0001,
niklase@google.com470e71d2011-07-07 08:21:25 +000085 // not a module, triggered from the engine code
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000086 kTraceVideo = 0x0002,
niklase@google.com470e71d2011-07-07 08:21:25 +000087 // not a module, triggered from the utility code
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000088 kTraceUtility = 0x0003,
89 kTraceRtpRtcp = 0x0004,
90 kTraceTransport = 0x0005,
91 kTraceSrtp = 0x0006,
92 kTraceAudioCoding = 0x0007,
93 kTraceAudioMixerServer = 0x0008,
94 kTraceAudioMixerClient = 0x0009,
95 kTraceFile = 0x000a,
96 kTraceAudioProcessing = 0x000b,
97 kTraceVideoCoding = 0x0010,
98 kTraceVideoMixer = 0x0011,
99 kTraceAudioDevice = 0x0012,
100 kTraceVideoRenderer = 0x0014,
101 kTraceVideoCapture = 0x0015,
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000102 kTraceRemoteBitrateEstimator = 0x0017,
niklase@google.com470e71d2011-07-07 08:21:25 +0000103};
104
105enum TraceLevel
106{
107 kTraceNone = 0x0000, // no trace
108 kTraceStateInfo = 0x0001,
109 kTraceWarning = 0x0002,
110 kTraceError = 0x0004,
111 kTraceCritical = 0x0008,
112 kTraceApiCall = 0x0010,
113 kTraceDefault = 0x00ff,
114
115 kTraceModuleCall = 0x0020,
116 kTraceMemory = 0x0100, // memory info
117 kTraceTimer = 0x0200, // timing info
118 kTraceStream = 0x0400, // "continuous" stream of data
119
120 // used for debug purposes
121 kTraceDebug = 0x0800, // debug
122 kTraceInfo = 0x1000, // debug info
123
andrew@webrtc.org655d8f52012-11-20 07:34:45 +0000124 // Non-verbose level used by LS_INFO of logging.h. Do not use directly.
125 kTraceTerseInfo = 0x2000,
126
niklase@google.com470e71d2011-07-07 08:21:25 +0000127 kTraceAll = 0xffff
128};
129
130// External Trace API
andrew@webrtc.org23ec30b2012-11-15 05:33:25 +0000131class TraceCallback {
132 public:
133 virtual void Print(TraceLevel level, const char* message, int length) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
andrew@webrtc.org23ec30b2012-11-15 05:33:25 +0000135 protected:
136 virtual ~TraceCallback() {}
137 TraceCallback() {}
138};
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
140enum FileFormats
141{
142 kFileFormatWavFile = 1,
143 kFileFormatCompressedFile = 2,
niklase@google.com470e71d2011-07-07 08:21:25 +0000144 kFileFormatPreencodedFile = 4,
145 kFileFormatPcm16kHzFile = 7,
146 kFileFormatPcm8kHzFile = 8,
147 kFileFormatPcm32kHzFile = 9
148};
149
niklase@google.com470e71d2011-07-07 08:21:25 +0000150enum ProcessingTypes
151{
152 kPlaybackPerChannel = 0,
153 kPlaybackAllChannelsMixed,
154 kRecordingPerChannel,
andrew@webrtc.org21ab3ba2012-10-19 17:30:56 +0000155 kRecordingAllChannelsMixed,
156 kRecordingPreprocessing
niklase@google.com470e71d2011-07-07 08:21:25 +0000157};
158
pbos22993e12015-10-19 02:39:06 -0700159enum FrameType {
160 kEmptyFrame = 0,
161 kAudioFrameSpeech = 1,
162 kAudioFrameCN = 2,
163 kVideoFrameKey = 3,
164 kVideoFrameDelta = 4,
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000165};
166
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000167// Statistics for an RTCP channel
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000168struct RtcpStatistics {
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000169 RtcpStatistics()
170 : fraction_lost(0),
171 cumulative_lost(0),
172 extended_max_sequence_number(0),
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000173 jitter(0) {}
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000174
175 uint8_t fraction_lost;
176 uint32_t cumulative_lost;
177 uint32_t extended_max_sequence_number;
178 uint32_t jitter;
sprang@webrtc.orgfe5d36b2013-10-28 09:21:07 +0000179};
180
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000181class RtcpStatisticsCallback {
182 public:
183 virtual ~RtcpStatisticsCallback() {}
184
185 virtual void StatisticsUpdated(const RtcpStatistics& statistics,
186 uint32_t ssrc) = 0;
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000187 virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000188};
189
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000190// Statistics for RTCP packet types.
191struct RtcpPacketTypeCounter {
192 RtcpPacketTypeCounter()
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000193 : first_packet_time_ms(-1),
194 nack_packets(0),
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000195 fir_packets(0),
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000196 pli_packets(0),
197 nack_requests(0),
198 unique_nack_requests(0) {}
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000199
200 void Add(const RtcpPacketTypeCounter& other) {
201 nack_packets += other.nack_packets;
202 fir_packets += other.fir_packets;
203 pli_packets += other.pli_packets;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000204 nack_requests += other.nack_requests;
205 unique_nack_requests += other.unique_nack_requests;
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000206 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 oldest time.
210 first_packet_time_ms = other.first_packet_time_ms;
211 }
212 }
213
214 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:02 +0000216 }
217
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000218 int UniqueNackRequestsInPercent() const {
219 if (nack_requests == 0) {
220 return 0;
221 }
222 return static_cast<int>(
223 (unique_nack_requests * 100.0f / nack_requests) + 0.5f);
224 }
225
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000226 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:30 +0000231 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets.
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000232};
233
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000234class 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:11 +0000242// Rate statistics for a stream.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000243struct BitrateStatistics {
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000244 BitrateStatistics() : bitrate_bps(0), packet_rate(0), timestamp_ms(0) {}
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000245
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000246 uint32_t bitrate_bps; // Bitrate in bits per second.
247 uint32_t packet_rate; // Packet rate in packets per second.
248 uint64_t timestamp_ms; // Ntp timestamp in ms at time of rate estimation.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000249};
250
251// Callback, used to notify an observer whenever new rates have been estimated.
252class BitrateStatisticsObserver {
253 public:
254 virtual ~BitrateStatisticsObserver() {}
255
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000256 virtual void Notify(const BitrateStatistics& total_stats,
257 const BitrateStatistics& retransmit_stats,
258 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000259};
260
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000261struct FrameCounts {
262 FrameCounts() : key_frames(0), delta_frames(0) {}
263 int key_frames;
264 int delta_frames;
265};
266
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000267// Callback, used to notify an observer whenever frame counts have been updated.
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000268class FrameCountObserver {
269 public:
sprang@webrtc.org72964bd2013-11-21 09:09:54 +0000270 virtual ~FrameCountObserver() {}
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000271 virtual void FrameCountUpdated(const FrameCounts& frame_counts,
272 uint32_t ssrc) = 0;
sprang@webrtc.orgdc50aae2013-11-20 16:47:07 +0000273};
274
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000275// Callback, used to notify an observer whenever the send-side delay is updated.
276class SendSideDelayObserver {
277 public:
278 virtual ~SendSideDelayObserver() {}
279 virtual void SendSideDelayUpdated(int avg_delay_ms,
280 int max_delay_ms,
281 uint32_t ssrc) = 0;
282};
283
niklase@google.com470e71d2011-07-07 08:21:25 +0000284// ==================================================================
285// Voice specific types
286// ==================================================================
287
288// Each codec supported can be described by this structure.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000289struct CodecInst {
290 int pltype;
291 char plname[RTP_PAYLOAD_NAME_SIZE];
292 int plfreq;
293 int pacsize;
294 int channels;
295 int rate; // bits/sec unlike {start,min,max}Bitrate elsewhere in this file!
296
297 bool operator==(const CodecInst& other) const {
298 return pltype == other.pltype &&
299 (STR_CASE_CMP(plname, other.plname) == 0) &&
300 plfreq == other.plfreq &&
301 pacsize == other.pacsize &&
302 channels == other.channels &&
303 rate == other.rate;
304 }
305
306 bool operator!=(const CodecInst& other) const {
307 return !(*this == other);
308 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000309};
310
niklase@google.com470e71d2011-07-07 08:21:25 +0000311// RTP
312enum {kRtpCsrcSize = 15}; // RFC 3550 page 13
313
314enum RTPDirections
315{
316 kRtpIncoming = 0,
317 kRtpOutgoing
318};
319
320enum PayloadFrequencies
321{
322 kFreq8000Hz = 8000,
323 kFreq16000Hz = 16000,
324 kFreq32000Hz = 32000
325};
326
327enum VadModes // degree of bandwidth reduction
328{
329 kVadConventional = 0, // lowest reduction
330 kVadAggressiveLow,
331 kVadAggressiveMid,
332 kVadAggressiveHigh // highest reduction
333};
334
335struct NetworkStatistics // NETEQ statistics
336{
337 // current jitter buffer size in ms
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000338 uint16_t currentBufferSize;
niklase@google.com470e71d2011-07-07 08:21:25 +0000339 // preferred (optimal) buffer size in ms
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000340 uint16_t preferredBufferSize;
henrik.lundin@webrtc.orgd4398702012-01-04 13:09:55 +0000341 // adding extra delay due to "peaky jitter"
342 bool jitterPeaksFound;
henrik.lundin@webrtc.org8768f162014-10-09 12:58:45 +0000343 // Loss rate (network + late); fraction between 0 and 1, scaled to Q14.
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000344 uint16_t currentPacketLossRate;
henrik.lundin@webrtc.org8768f162014-10-09 12:58:45 +0000345 // Late loss rate; fraction between 0 and 1, scaled to Q14.
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000346 uint16_t currentDiscardRate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000347 // fraction (of original stream) of synthesized audio inserted through
niklase@google.com470e71d2011-07-07 08:21:25 +0000348 // expansion (in Q14)
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000349 uint16_t currentExpandRate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000350 // fraction (of original stream) of synthesized speech inserted through
351 // expansion (in Q14)
352 uint16_t currentSpeechExpandRate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 // fraction of synthesized speech inserted through pre-emptive expansion
354 // (in Q14)
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000355 uint16_t currentPreemptiveRate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 // fraction of data removed through acceleration (in Q14)
pbos@webrtc.org77f6b212013-05-03 12:02:11 +0000357 uint16_t currentAccelerateRate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000358 // fraction of data coming from secondary decoding (in Q14)
359 uint16_t currentSecondaryDecodedRate;
henrik.lundin@webrtc.orgd4398702012-01-04 13:09:55 +0000360 // clock-drift in parts-per-million (negative or positive)
361 int32_t clockDriftPPM;
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000362 // average packet waiting time in the jitter buffer (ms)
363 int meanWaitingTimeMs;
364 // median packet waiting time in the jitter buffer (ms)
365 int medianWaitingTimeMs;
henrik.lundin@webrtc.org053c7992012-01-12 14:16:44 +0000366 // min packet waiting time in the jitter buffer (ms)
367 int minWaitingTimeMs;
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000368 // max packet waiting time in the jitter buffer (ms)
369 int maxWaitingTimeMs;
roosa@google.comb8ba4d82012-12-14 00:06:18 +0000370 // added samples in off mode due to packet loss
Peter Kastingdce40cf2015-08-24 14:52:23 -0700371 size_t addedSamples;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372};
373
wu@webrtc.org24301a62013-12-13 19:17:43 +0000374// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
375struct AudioDecodingCallStats {
376 AudioDecodingCallStats()
377 : calls_to_silence_generator(0),
378 calls_to_neteq(0),
379 decoded_normal(0),
380 decoded_plc(0),
381 decoded_cng(0),
382 decoded_plc_cng(0) {}
383
384 int calls_to_silence_generator; // Number of calls where silence generated,
385 // and NetEq was disengaged from decoding.
386 int calls_to_neteq; // Number of calls to NetEq.
387 int decoded_normal; // Number of calls where audio RTP packet decoded.
388 int decoded_plc; // Number of calls resulted in PLC.
389 int decoded_cng; // Number of calls where comfort noise generated due to DTX.
390 int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG.
391};
392
niklase@google.com470e71d2011-07-07 08:21:25 +0000393typedef struct
394{
395 int min; // minumum
396 int max; // maximum
397 int average; // average
398} StatVal;
399
400typedef struct // All levels are reported in dBm0
401{
402 StatVal speech_rx; // long-term speech levels on receiving side
403 StatVal speech_tx; // long-term speech levels on transmitting side
404 StatVal noise_rx; // long-term noise/silence levels on receiving side
405 StatVal noise_tx; // long-term noise/silence levels on transmitting side
406} LevelStatistics;
407
408typedef struct // All levels are reported in dB
409{
410 StatVal erl; // Echo Return Loss
411 StatVal erle; // Echo Return Loss Enhancement
412 StatVal rerl; // RERL = ERL + ERLE
413 // Echo suppression inside EC at the point just before its NLP
414 StatVal a_nlp;
415} EchoStatistics;
416
niklase@google.com470e71d2011-07-07 08:21:25 +0000417enum NsModes // type of Noise Suppression
418{
419 kNsUnchanged = 0, // previously set mode
420 kNsDefault, // platform default
421 kNsConference, // conferencing default
422 kNsLowSuppression, // lowest suppression
423 kNsModerateSuppression,
424 kNsHighSuppression,
425 kNsVeryHighSuppression, // highest suppression
426};
427
428enum AgcModes // type of Automatic Gain Control
429{
430 kAgcUnchanged = 0, // previously set mode
431 kAgcDefault, // platform default
432 // adaptive mode for use when analog volume control exists (e.g. for
433 // PC softphone)
434 kAgcAdaptiveAnalog,
435 // scaling takes place in the digital domain (e.g. for conference servers
436 // and embedded devices)
437 kAgcAdaptiveDigital,
andrew@webrtc.org80124742012-03-08 17:54:24 +0000438 // can be used on embedded devices where the capture signal level
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 // is predictable
440 kAgcFixedDigital
441};
442
443// EC modes
444enum EcModes // type of Echo Control
445{
446 kEcUnchanged = 0, // previously set mode
447 kEcDefault, // platform default
448 kEcConference, // conferencing default (aggressive AEC)
449 kEcAec, // Acoustic Echo Cancellation
450 kEcAecm, // AEC mobile
451};
452
453// AECM modes
454enum AecmModes // mode of AECM
455{
456 kAecmQuietEarpieceOrHeadset = 0,
457 // Quiet earpiece or headset use
458 kAecmEarpiece, // most earpiece use
459 kAecmLoudEarpiece, // Loud earpiece or quiet speakerphone use
460 kAecmSpeakerphone, // most speakerphone use (default)
461 kAecmLoudSpeakerphone // Loud speakerphone
462};
463
464// AGC configuration
465typedef struct
466{
467 unsigned short targetLeveldBOv;
468 unsigned short digitalCompressionGaindB;
469 bool limiterEnable;
470} AgcConfig; // AGC configuration parameters
471
472enum StereoChannel
473{
474 kStereoLeft = 0,
475 kStereoRight,
476 kStereoBoth
477};
478
479// Audio device layers
480enum AudioLayers
481{
482 kAudioPlatformDefault = 0,
483 kAudioWindowsWave = 1,
484 kAudioWindowsCore = 2,
485 kAudioLinuxAlsa = 3,
486 kAudioLinuxPulse = 4
487};
488
henrika@webrtc.org66803482014-04-17 10:45:01 +0000489// TODO(henrika): to be removed.
niklase@google.com470e71d2011-07-07 08:21:25 +0000490enum NetEqModes // NetEQ playout configurations
491{
492 // Optimized trade-off between low delay and jitter robustness for two-way
493 // communication.
494 kNetEqDefault = 0,
495 // Improved jitter robustness at the cost of increased delay. Can be
496 // used in one-way communication.
497 kNetEqStreaming = 1,
498 // Optimzed for decodability of fax signals rather than for perceived audio
499 // quality.
500 kNetEqFax = 2,
roosa@google.comb7186192012-12-12 21:59:14 +0000501 // Minimal buffer management. Inserts zeros for lost packets and during
502 // buffer increases.
503 kNetEqOff = 3,
niklase@google.com470e71d2011-07-07 08:21:25 +0000504};
505
henrika@webrtc.org66803482014-04-17 10:45:01 +0000506// TODO(henrika): to be removed.
niklase@google.com470e71d2011-07-07 08:21:25 +0000507enum OnHoldModes // On Hold direction
508{
509 kHoldSendAndPlay = 0, // Put both sending and playing in on-hold state.
510 kHoldSendOnly, // Put only sending in on-hold state.
511 kHoldPlayOnly // Put only playing in on-hold state.
512};
513
henrika@webrtc.org66803482014-04-17 10:45:01 +0000514// TODO(henrika): to be removed.
niklase@google.com470e71d2011-07-07 08:21:25 +0000515enum AmrMode
516{
517 kRfc3267BwEfficient = 0,
518 kRfc3267OctetAligned = 1,
519 kRfc3267FileStorage = 2,
520};
521
522// ==================================================================
523// Video specific types
524// ==================================================================
525
526// Raw video types
527enum RawVideoType
528{
529 kVideoI420 = 0,
530 kVideoYV12 = 1,
531 kVideoYUY2 = 2,
532 kVideoUYVY = 3,
533 kVideoIYUV = 4,
534 kVideoARGB = 5,
535 kVideoRGB24 = 6,
536 kVideoRGB565 = 7,
537 kVideoARGB4444 = 8,
538 kVideoARGB1555 = 9,
539 kVideoMJPEG = 10,
540 kVideoNV12 = 11,
541 kVideoNV21 = 12,
mikhal@webrtc.orgc00f91d2012-01-03 18:49:15 +0000542 kVideoBGRA = 13,
niklase@google.com470e71d2011-07-07 08:21:25 +0000543 kVideoUnknown = 99
544};
545
546// Video codec
547enum { kConfigParameterSize = 128};
548enum { kPayloadNameSize = 32};
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000549enum { kMaxSimulcastStreams = 4};
sprangce4aef12015-11-02 07:23:20 -0800550enum { kMaxSpatialLayers = 5 };
pwestin@webrtc.orgdb221d22011-12-02 11:31:08 +0000551enum { kMaxTemporalStreams = 4};
niklase@google.com470e71d2011-07-07 08:21:25 +0000552
niklase@google.com470e71d2011-07-07 08:21:25 +0000553enum VideoCodecComplexity
554{
555 kComplexityNormal = 0,
556 kComplexityHigh = 1,
557 kComplexityHigher = 2,
558 kComplexityMax = 3
559};
560
561enum VideoCodecProfile
562{
563 kProfileBase = 0x00,
564 kProfileMain = 0x01
565};
566
stefan@webrtc.orgefd0a482011-12-29 10:12:35 +0000567enum VP8ResilienceMode {
568 kResilienceOff, // The stream produced by the encoder requires a
569 // recovery frame (typically a key frame) to be
570 // decodable after a packet loss.
571 kResilientStream, // A stream produced by the encoder is resilient to
572 // packet losses, but packets within a frame subsequent
573 // to a loss can't be decoded.
574 kResilientFrames // Same as kResilientStream but with added resilience
575 // within a frame.
576};
577
niklase@google.com470e71d2011-07-07 08:21:25 +0000578// VP8 specific
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000579struct VideoCodecVP8 {
580 bool pictureLossIndicationOn;
581 bool feedbackModeOn;
582 VideoCodecComplexity complexity;
583 VP8ResilienceMode resilience;
584 unsigned char numberOfTemporalLayers;
585 bool denoisingOn;
586 bool errorConcealmentOn;
587 bool automaticResizeOn;
588 bool frameDroppingOn;
589 int keyFrameInterval;
590
591 bool operator==(const VideoCodecVP8& other) const {
592 return pictureLossIndicationOn == other.pictureLossIndicationOn &&
593 feedbackModeOn == other.feedbackModeOn &&
594 complexity == other.complexity &&
595 resilience == other.resilience &&
596 numberOfTemporalLayers == other.numberOfTemporalLayers &&
597 denoisingOn == other.denoisingOn &&
598 errorConcealmentOn == other.errorConcealmentOn &&
599 automaticResizeOn == other.automaticResizeOn &&
600 frameDroppingOn == other.frameDroppingOn &&
601 keyFrameInterval == other.keyFrameInterval;
602 }
603
604 bool operator!=(const VideoCodecVP8& other) const {
605 return !(*this == other);
606 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000607};
608
asaperssona9455ab2015-07-31 06:10:09 -0700609// VP9 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000610struct VideoCodecVP9 {
611 VideoCodecComplexity complexity;
612 int resilience;
613 unsigned char numberOfTemporalLayers;
614 bool denoisingOn;
615 bool frameDroppingOn;
616 int keyFrameInterval;
617 bool adaptiveQpMode;
Marcof3507202015-09-17 12:16:04 -0700618 bool automaticResizeOn;
asaperssona9455ab2015-07-31 06:10:09 -0700619 unsigned char numberOfSpatialLayers;
620 bool flexibleMode;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000621};
622
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000623// H264 specific.
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000624struct VideoCodecH264 {
625 VideoCodecProfile profile;
626 bool frameDroppingOn;
627 int keyFrameInterval;
628 // These are NULL/0 if not externally negotiated.
629 const uint8_t* spsData;
630 size_t spsLen;
631 const uint8_t* ppsData;
632 size_t ppsLen;
stefan@webrtc.orgb9f54532014-07-04 12:42:07 +0000633};
634
niklase@google.com470e71d2011-07-07 08:21:25 +0000635// Video codec types
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000636enum VideoCodecType {
637 kVideoCodecVP8,
638 kVideoCodecVP9,
639 kVideoCodecH264,
640 kVideoCodecI420,
641 kVideoCodecRED,
642 kVideoCodecULPFEC,
643 kVideoCodecGeneric,
644 kVideoCodecUnknown
niklase@google.com470e71d2011-07-07 08:21:25 +0000645};
646
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000647union VideoCodecUnion {
648 VideoCodecVP8 VP8;
649 VideoCodecVP9 VP9;
650 VideoCodecH264 H264;
niklase@google.com470e71d2011-07-07 08:21:25 +0000651};
652
phoglund@webrtc.org8bfee842012-02-17 09:32:48 +0000653
654// Simulcast is when the same stream is encoded multiple times with different
655// settings such as resolution.
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000656struct SimulcastStream {
657 unsigned short width;
658 unsigned short height;
659 unsigned char numberOfTemporalLayers;
660 unsigned int maxBitrate; // kilobits/sec.
661 unsigned int targetBitrate; // kilobits/sec.
662 unsigned int minBitrate; // kilobits/sec.
663 unsigned int qpMax; // minimum quality
664
665 bool operator==(const SimulcastStream& other) const {
666 return width == other.width &&
667 height == other.height &&
668 numberOfTemporalLayers == other.numberOfTemporalLayers &&
669 maxBitrate == other.maxBitrate &&
670 targetBitrate == other.targetBitrate &&
671 minBitrate == other.minBitrate &&
672 qpMax == other.qpMax;
673 }
674
675 bool operator!=(const SimulcastStream& other) const {
676 return !(*this == other);
677 }
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000678};
679
sprangce4aef12015-11-02 07:23:20 -0800680struct SpatialLayer {
681 int scaling_factor_num;
682 int scaling_factor_den;
683 int target_bitrate_bps;
684 // TODO(ivica): Add max_quantizer and min_quantizer?
685};
686
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000687enum VideoCodecMode {
688 kRealtimeVideo,
689 kScreensharing
690};
691
niklase@google.com470e71d2011-07-07 08:21:25 +0000692// Common video codec properties
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000693struct VideoCodec {
694 VideoCodecType codecType;
695 char plName[kPayloadNameSize];
696 unsigned char plType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000698 unsigned short width;
699 unsigned short height;
niklase@google.com470e71d2011-07-07 08:21:25 +0000700
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000701 unsigned int startBitrate; // kilobits/sec.
702 unsigned int maxBitrate; // kilobits/sec.
703 unsigned int minBitrate; // kilobits/sec.
pbos@webrtc.org3c412b22014-03-24 12:36:52 +0000704 unsigned int targetBitrate; // kilobits/sec.
705
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000706 unsigned char maxFramerate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000707
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000708 VideoCodecUnion codecSpecific;
niklase@google.com470e71d2011-07-07 08:21:25 +0000709
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000710 unsigned int qpMax;
711 unsigned char numberOfSimulcastStreams;
712 SimulcastStream simulcastStream[kMaxSimulcastStreams];
sprangce4aef12015-11-02 07:23:20 -0800713 SpatialLayer spatialLayers[kMaxSpatialLayers];
stefan@webrtc.orgeb917922013-02-18 14:40:18 +0000714
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000715 VideoCodecMode mode;
andresp@webrtc.org185bae42013-05-14 08:02:25 +0000716
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000717 // When using an external encoder/decoder this allows to pass
718 // extra options without requiring webrtc to be aware of them.
719 Config* extra_options;
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000720
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000721 bool operator==(const VideoCodec& other) const {
722 bool ret = codecType == other.codecType &&
723 (STR_CASE_CMP(plName, other.plName) == 0) &&
724 plType == other.plType &&
725 width == other.width &&
726 height == other.height &&
727 startBitrate == other.startBitrate &&
728 maxBitrate == other.maxBitrate &&
729 minBitrate == other.minBitrate &&
pbos@webrtc.org3c412b22014-03-24 12:36:52 +0000730 targetBitrate == other.targetBitrate &&
mallinath@webrtc.org0209e562014-03-21 00:41:28 +0000731 maxFramerate == other.maxFramerate &&
732 qpMax == other.qpMax &&
733 numberOfSimulcastStreams == other.numberOfSimulcastStreams &&
734 mode == other.mode;
735 if (ret && codecType == kVideoCodecVP8) {
736 ret &= (codecSpecific.VP8 == other.codecSpecific.VP8);
737 }
738
739 for (unsigned char i = 0; i < other.numberOfSimulcastStreams && ret; ++i) {
740 ret &= (simulcastStream[i] == other.simulcastStream[i]);
741 }
742 return ret;
743 }
744
745 bool operator!=(const VideoCodec& other) const {
746 return !(*this == other);
747 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000748};
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000749
750// Bandwidth over-use detector options. These are used to drive
751// experimentation with bandwidth estimation parameters.
752// See modules/remote_bitrate_estimator/overuse_detector.h
753struct OverUseDetectorOptions {
754 OverUseDetectorOptions()
755 : initial_slope(8.0/512.0),
756 initial_offset(0),
757 initial_e(),
758 initial_process_noise(),
759 initial_avg_noise(0.0),
Stefan Holmer86479222015-07-10 11:28:37 +0200760 initial_var_noise(50) {
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000761 initial_e[0][0] = 100;
762 initial_e[1][1] = 1e-1;
763 initial_e[0][1] = initial_e[1][0] = 0;
stefanc62642c2015-07-07 04:20:34 -0700764 initial_process_noise[0] = 1e-13;
Stefan Holmer86479222015-07-10 11:28:37 +0200765 initial_process_noise[1] = 1e-2;
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000766 }
767 double initial_slope;
768 double initial_offset;
769 double initial_e[2][2];
770 double initial_process_noise[2];
771 double initial_avg_noise;
772 double initial_var_noise;
astor@webrtc.orgbd7aeba2012-06-26 10:47:04 +0000773};
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000774
wu@webrtc.orga9890802013-12-13 00:21:03 +0000775// This structure will have the information about when packet is actually
776// received by socket.
777struct PacketTime {
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000778 PacketTime() : timestamp(-1), not_before(-1) {}
779 PacketTime(int64_t timestamp, int64_t not_before)
780 : timestamp(timestamp), not_before(not_before) {
wu@webrtc.orga9890802013-12-13 00:21:03 +0000781 }
782
henrike@webrtc.org82d3cb62014-04-29 17:50:47 +0000783 int64_t timestamp; // Receive time after socket delivers the data.
784 int64_t not_before; // Earliest possible time the data could have arrived,
785 // indicating the potential error in the |timestamp|
786 // value,in case the system is busy.
787 // For example, the time of the last select() call.
788 // If unknown, this value will be set to zero.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000789};
790
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000791struct RTPHeaderExtension {
sprang@webrtc.org30933902015-03-17 14:33:12 +0000792 RTPHeaderExtension();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000793
794 bool hasTransmissionTimeOffset;
795 int32_t transmissionTimeOffset;
796 bool hasAbsoluteSendTime;
797 uint32_t absoluteSendTime;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000798 bool hasTransportSequenceNumber;
799 uint16_t transportSequenceNumber;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000800
801 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
802 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
803 bool hasAudioLevel;
Minyue4cee4192015-08-10 15:08:36 +0200804 bool voiceActivity;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000805 uint8_t audioLevel;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000806
807 // For Coordination of Video Orientation. See
808 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
809 // ts_126114v120700p.pdf
810 bool hasVideoRotation;
811 uint8_t videoRotation;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000812};
813
814struct RTPHeader {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000815 RTPHeader();
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000816
817 bool markerBit;
818 uint8_t payloadType;
819 uint16_t sequenceNumber;
820 uint32_t timestamp;
821 uint32_t ssrc;
822 uint8_t numCSRCs;
823 uint32_t arrOfCSRCs[kRtpCsrcSize];
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000824 size_t paddingLength;
825 size_t headerLength;
solenberg@webrtc.orgb1f50102014-03-24 10:38:25 +0000826 int payload_type_frequency;
827 RTPHeaderExtension extension;
828};
829
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000830struct RtpPacketCounter {
831 RtpPacketCounter()
832 : header_bytes(0),
833 payload_bytes(0),
834 padding_bytes(0),
835 packets(0) {}
836
837 void Add(const RtpPacketCounter& other) {
838 header_bytes += other.header_bytes;
839 payload_bytes += other.payload_bytes;
840 padding_bytes += other.padding_bytes;
841 packets += other.packets;
842 }
843
844 void AddPacket(size_t packet_length, const RTPHeader& header) {
845 ++packets;
846 header_bytes += header.headerLength;
847 padding_bytes += header.paddingLength;
848 payload_bytes +=
849 packet_length - (header.headerLength + header.paddingLength);
850 }
851
852 size_t TotalBytes() const {
853 return header_bytes + payload_bytes + padding_bytes;
854 }
855
856 size_t header_bytes; // Number of bytes used by RTP headers.
857 size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
858 size_t padding_bytes; // Number of padding bytes.
859 uint32_t packets; // Number of packets.
860};
861
862// Data usage statistics for a (rtp) stream.
863struct StreamDataCounters {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000864 StreamDataCounters();
asapersson@webrtc.org44149392015-02-04 08:34:47 +0000865
866 void Add(const StreamDataCounters& other) {
867 transmitted.Add(other.transmitted);
868 retransmitted.Add(other.retransmitted);
869 fec.Add(other.fec);
870 if (other.first_packet_time_ms != -1 &&
871 (other.first_packet_time_ms < first_packet_time_ms ||
872 first_packet_time_ms == -1)) {
873 // Use oldest time.
874 first_packet_time_ms = other.first_packet_time_ms;
875 }
876 }
877
878 int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
879 return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
880 }
881
882 // Returns the number of bytes corresponding to the actual media payload (i.e.
883 // RTP headers, padding, retransmissions and fec packets are excluded).
884 // Note this function does not have meaning for an RTX stream.
885 size_t MediaPayloadBytes() const {
886 return transmitted.payload_bytes - retransmitted.payload_bytes -
887 fec.payload_bytes;
888 }
889
890 int64_t first_packet_time_ms; // Time when first packet is sent/received.
891 RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
892 RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
893 RtpPacketCounter fec; // Number of redundancy packets/bytes.
894};
895
896// Callback, called whenever byte/packet counts have been updated.
897class StreamDataCountersCallback {
898 public:
899 virtual ~StreamDataCountersCallback() {}
900
901 virtual void DataCountersUpdated(const StreamDataCounters& counters,
902 uint32_t ssrc) = 0;
903};
pbosda903ea2015-10-02 02:36:56 -0700904
905// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
906// RTCP mode is described by RFC 5506.
907enum class RtcpMode { kOff, kCompound, kReducedSize };
908
niklase@google.com470e71d2011-07-07 08:21:25 +0000909} // namespace webrtc
andrew@webrtc.orgeda189b2013-09-09 17:50:10 +0000910
911#endif // WEBRTC_COMMON_TYPES_H_