andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1 | /* |
| 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.org | 5cf83f4 | 2013-09-09 17:50:10 | [diff] [blame] | 11 | #ifndef WEBRTC_COMMON_TYPES_H_ |
| 12 | #define WEBRTC_COMMON_TYPES_H_ |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 13 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 14 | #include <stddef.h> |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 15 | #include <string.h> |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 16 | |
| 17 | #include <string> |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
kwiberg | c1a5e1b | 2016-11-29 13:30:40 | [diff] [blame] | 20 | #include "webrtc/base/checks.h" |
Erik Språng | fafcfc0 | 2016-11-16 15:41:30 | [diff] [blame] | 21 | #include "webrtc/base/optional.h" |
magjed | 78706f4 | 2016-09-08 10:24:58 | [diff] [blame] | 22 | #include "webrtc/common_video/rotation.h" |
andrew@webrtc.org | 5cf83f4 | 2013-09-09 17:50:10 | [diff] [blame] | 23 | #include "webrtc/typedefs.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 24 | |
| 25 | #if defined(_MSC_VER) |
| 26 | // Disable "new behavior: elements of array will be default initialized" |
| 27 | // warning. Affects OverUseDetectorOptions. |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 28 | #pragma warning(disable : 4351) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 29 | #endif |
| 30 | |
kwiberg | 15b966d | 2016-09-29 00:42:01 | [diff] [blame] | 31 | #if defined(WEBRTC_EXPORT) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 32 | #define WEBRTC_DLLEXPORT _declspec(dllexport) |
kwiberg | 15b966d | 2016-09-29 00:42:01 | [diff] [blame] | 33 | #elif defined(WEBRTC_DLL) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 34 | #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öm | cd71dc6 | 2016-02-26 15:31:37 | [diff] [blame] | 43 | #define RTP_PAYLOAD_NAME_SIZE 32u |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 44 | |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 45 | #if defined(WEBRTC_WIN) || defined(WIN32) |
andrew@webrtc.org | 5cf83f4 | 2013-09-09 17:50:10 | [diff] [blame] | 46 | // 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 55 | namespace webrtc { |
| 56 | |
tommi | a6d985c | 2016-06-15 17:30:14 | [diff] [blame] | 57 | class RewindableStream { |
| 58 | public: |
| 59 | virtual ~RewindableStream() {} |
| 60 | virtual int Rewind() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 61 | }; |
| 62 | |
tommi | a6d985c | 2016-06-15 17:30:14 | [diff] [blame] | 63 | class 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 | |
| 70 | class 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 75 | }; |
| 76 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 77 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 99 | }; |
| 100 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 101 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 109 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 110 | kTraceModuleCall = 0x0020, |
| 111 | kTraceMemory = 0x0100, // memory info |
| 112 | kTraceTimer = 0x0200, // timing info |
| 113 | kTraceStream = 0x0400, // "continuous" stream of data |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 114 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 115 | // used for debug purposes |
| 116 | kTraceDebug = 0x0800, // debug |
| 117 | kTraceInfo = 0x1000, // debug info |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 118 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 119 | // Non-verbose level used by LS_INFO of logging.h. Do not use directly. |
| 120 | kTraceTerseInfo = 0x2000, |
andrew@webrtc.org | bc687c5 | 2012-11-20 07:34:45 | [diff] [blame] | 121 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 122 | kTraceAll = 0xffff |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | // External Trace API |
andrew@webrtc.org | d75680a | 2012-11-15 05:33:25 | [diff] [blame] | 126 | class TraceCallback { |
| 127 | public: |
| 128 | virtual void Print(TraceLevel level, const char* message, int length) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 129 | |
andrew@webrtc.org | d75680a | 2012-11-15 05:33:25 | [diff] [blame] | 130 | protected: |
| 131 | virtual ~TraceCallback() {} |
| 132 | TraceCallback() {} |
| 133 | }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 134 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 135 | enum FileFormats { |
| 136 | kFileFormatWavFile = 1, |
| 137 | kFileFormatCompressedFile = 2, |
| 138 | kFileFormatPreencodedFile = 4, |
| 139 | kFileFormatPcm16kHzFile = 7, |
| 140 | kFileFormatPcm8kHzFile = 8, |
| 141 | kFileFormatPcm32kHzFile = 9 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 142 | }; |
| 143 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 144 | enum ProcessingTypes { |
| 145 | kPlaybackPerChannel = 0, |
| 146 | kPlaybackAllChannelsMixed, |
| 147 | kRecordingPerChannel, |
| 148 | kRecordingAllChannelsMixed, |
| 149 | kRecordingPreprocessing |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 150 | }; |
| 151 | |
pbos | b63d8ad | 2015-10-19 09:39:06 | [diff] [blame] | 152 | enum FrameType { |
| 153 | kEmptyFrame = 0, |
| 154 | kAudioFrameSpeech = 1, |
| 155 | kAudioFrameCN = 2, |
| 156 | kVideoFrameKey = 3, |
| 157 | kVideoFrameDelta = 4, |
sprang@webrtc.org | 5fdd10a | 2013-12-04 15:09:27 | [diff] [blame] | 158 | }; |
| 159 | |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 160 | // Statistics for an RTCP channel |
sprang@webrtc.org | 2714c79 | 2013-10-28 09:21:07 | [diff] [blame] | 161 | struct RtcpStatistics { |
sprang@webrtc.org | 2714c79 | 2013-10-28 09:21:07 | [diff] [blame] | 162 | RtcpStatistics() |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 163 | : fraction_lost(0), |
| 164 | cumulative_lost(0), |
| 165 | extended_max_sequence_number(0), |
| 166 | jitter(0) {} |
sprang@webrtc.org | 2714c79 | 2013-10-28 09:21:07 | [diff] [blame] | 167 | |
| 168 | uint8_t fraction_lost; |
| 169 | uint32_t cumulative_lost; |
| 170 | uint32_t extended_max_sequence_number; |
| 171 | uint32_t jitter; |
sprang@webrtc.org | 2714c79 | 2013-10-28 09:21:07 | [diff] [blame] | 172 | }; |
| 173 | |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 174 | class RtcpStatisticsCallback { |
| 175 | public: |
| 176 | virtual ~RtcpStatisticsCallback() {} |
| 177 | |
| 178 | virtual void StatisticsUpdated(const RtcpStatistics& statistics, |
| 179 | uint32_t ssrc) = 0; |
pbos@webrtc.org | 1a36f78 | 2014-12-18 13:50:16 | [diff] [blame] | 180 | virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0; |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 181 | }; |
| 182 | |
asapersson@webrtc.org | 4a15560 | 2014-02-19 11:59:02 | [diff] [blame] | 183 | // Statistics for RTCP packet types. |
| 184 | struct RtcpPacketTypeCounter { |
| 185 | RtcpPacketTypeCounter() |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 186 | : 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.org | 4a15560 | 2014-02-19 11:59:02 | [diff] [blame] | 192 | |
| 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.org | 2ba45ee | 2014-10-29 12:42:30 | [diff] [blame] | 197 | nack_requests += other.nack_requests; |
| 198 | unique_nack_requests += other.unique_nack_requests; |
asapersson@webrtc.org | c76c553 | 2014-12-16 12:03:11 | [diff] [blame] | 199 | if (other.first_packet_time_ms != -1 && |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 200 | (other.first_packet_time_ms < first_packet_time_ms || |
| 201 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | c76c553 | 2014-12-16 12:03:11 | [diff] [blame] | 202 | // Use oldest time. |
| 203 | first_packet_time_ms = other.first_packet_time_ms; |
| 204 | } |
| 205 | } |
| 206 | |
sprang | 22c956d | 2016-02-24 15:55:00 | [diff] [blame] | 207 | 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.org | c76c553 | 2014-12-16 12:03:11 | [diff] [blame] | 221 | int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { |
| 222 | return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms); |
asapersson@webrtc.org | 4a15560 | 2014-02-19 11:59:02 | [diff] [blame] | 223 | } |
| 224 | |
asapersson@webrtc.org | 2ba45ee | 2014-10-29 12:42:30 | [diff] [blame] | 225 | int UniqueNackRequestsInPercent() const { |
| 226 | if (nack_requests == 0) { |
| 227 | return 0; |
| 228 | } |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 229 | return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) + |
| 230 | 0.5f); |
asapersson@webrtc.org | 2ba45ee | 2014-10-29 12:42:30 | [diff] [blame] | 231 | } |
| 232 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 233 | 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.org | 2ba45ee | 2014-10-29 12:42:30 | [diff] [blame] | 238 | uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. |
asapersson@webrtc.org | 4a15560 | 2014-02-19 11:59:02 | [diff] [blame] | 239 | }; |
| 240 | |
pbos@webrtc.org | eb1c2b5 | 2015-02-19 12:47:00 | [diff] [blame] | 241 | class RtcpPacketTypeCounterObserver { |
| 242 | public: |
| 243 | virtual ~RtcpPacketTypeCounterObserver() {} |
| 244 | virtual void RtcpPacketTypesCounterUpdated( |
| 245 | uint32_t ssrc, |
| 246 | const RtcpPacketTypeCounter& packet_counter) = 0; |
| 247 | }; |
| 248 | |
asapersson@webrtc.org | c76c553 | 2014-12-16 12:03:11 | [diff] [blame] | 249 | // Rate statistics for a stream. |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 250 | struct BitrateStatistics { |
sprang | 4c991f1 | 2016-07-13 16:11:28 | [diff] [blame] | 251 | BitrateStatistics() : bitrate_bps(0), packet_rate(0) {} |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 252 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 253 | uint32_t bitrate_bps; // Bitrate in bits per second. |
| 254 | uint32_t packet_rate; // Packet rate in packets per second. |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | // Callback, used to notify an observer whenever new rates have been estimated. |
| 258 | class BitrateStatisticsObserver { |
| 259 | public: |
| 260 | virtual ~BitrateStatisticsObserver() {} |
| 261 | |
sprang | 4c991f1 | 2016-07-13 16:11:28 | [diff] [blame] | 262 | virtual void Notify(uint32_t total_bitrate_bps, |
| 263 | uint32_t retransmit_bitrate_bps, |
stefan@webrtc.org | 5232267 | 2014-11-05 14:05:29 | [diff] [blame] | 264 | uint32_t ssrc) = 0; |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 265 | }; |
| 266 | |
pbos@webrtc.org | 1a36f78 | 2014-12-18 13:50:16 | [diff] [blame] | 267 | struct FrameCounts { |
| 268 | FrameCounts() : key_frames(0), delta_frames(0) {} |
| 269 | int key_frames; |
| 270 | int delta_frames; |
| 271 | }; |
| 272 | |
asapersson@webrtc.org | c76c553 | 2014-12-16 12:03:11 | [diff] [blame] | 273 | // Callback, used to notify an observer whenever frame counts have been updated. |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 274 | class FrameCountObserver { |
| 275 | public: |
sprang@webrtc.org | 21dc10d | 2013-11-21 09:09:54 | [diff] [blame] | 276 | virtual ~FrameCountObserver() {} |
pbos@webrtc.org | 1a36f78 | 2014-12-18 13:50:16 | [diff] [blame] | 277 | virtual void FrameCountUpdated(const FrameCounts& frame_counts, |
| 278 | uint32_t ssrc) = 0; |
sprang@webrtc.org | 4673674 | 2013-11-20 16:47:07 | [diff] [blame] | 279 | }; |
| 280 | |
stefan@webrtc.org | 55b0f2e | 2014-07-11 13:44:02 | [diff] [blame] | 281 | // Callback, used to notify an observer whenever the send-side delay is updated. |
| 282 | class 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 | |
asapersson | 86a285e | 2016-05-03 06:44:01 | [diff] [blame] | 290 | // 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. |
| 294 | class 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 | |
michaelt | 57beae3 | 2016-11-17 09:38:43 | [diff] [blame] | 302 | // Callback, used to notify an observer when the overhead per packet |
| 303 | // has changed. |
| 304 | class OverheadObserver { |
| 305 | public: |
| 306 | virtual ~OverheadObserver() = default; |
| 307 | virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0; |
| 308 | }; |
| 309 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 310 | // ================================================================== |
| 311 | // Voice specific types |
| 312 | // ================================================================== |
| 313 | |
| 314 | // Each codec supported can be described by this structure. |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 315 | struct CodecInst { |
| 316 | int pltype; |
| 317 | char plname[RTP_PAYLOAD_NAME_SIZE]; |
| 318 | int plfreq; |
| 319 | int pacsize; |
Peter Kasting | 80590d9 | 2016-01-13 00:26:35 | [diff] [blame] | 320 | size_t channels; |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 321 | 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) && |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 326 | plfreq == other.plfreq && pacsize == other.pacsize && |
| 327 | channels == other.channels && rate == other.rate; |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 328 | } |
| 329 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 330 | bool operator!=(const CodecInst& other) const { return !(*this == other); } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 331 | }; |
| 332 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 333 | // RTP |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 334 | enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 335 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 336 | enum PayloadFrequencies { |
| 337 | kFreq8000Hz = 8000, |
| 338 | kFreq16000Hz = 16000, |
| 339 | kFreq32000Hz = 32000 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 340 | }; |
| 341 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 342 | // Degree of bandwidth reduction. |
| 343 | enum VadModes { |
| 344 | kVadConventional = 0, // lowest reduction |
| 345 | kVadAggressiveLow, |
| 346 | kVadAggressiveMid, |
| 347 | kVadAggressiveHigh // highest reduction |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 348 | }; |
| 349 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 350 | // NETEQ statistics. |
| 351 | struct 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 387 | }; |
| 388 | |
wu@webrtc.org | 79d6daf | 2013-12-13 19:17:43 | [diff] [blame] | 389 | // Statistics for calls to AudioCodingModule::PlayoutData10Ms(). |
| 390 | struct 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.lundin | 4450c27 | 2016-09-20 08:47:12 | [diff] [blame] | 397 | decoded_plc_cng(0), |
| 398 | decoded_muted_output(0) {} |
wu@webrtc.org | 79d6daf | 2013-12-13 19:17:43 | [diff] [blame] | 399 | |
| 400 | int calls_to_silence_generator; // Number of calls where silence generated, |
| 401 | // and NetEq was disengaged from decoding. |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 402 | int calls_to_neteq; // Number of calls to NetEq. |
wu@webrtc.org | 79d6daf | 2013-12-13 19:17:43 | [diff] [blame] | 403 | int decoded_normal; // Number of calls where audio RTP packet decoded. |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 404 | int decoded_plc; // Number of calls resulted in PLC. |
wu@webrtc.org | 79d6daf | 2013-12-13 19:17:43 | [diff] [blame] | 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. |
henrik.lundin | 4450c27 | 2016-09-20 08:47:12 | [diff] [blame] | 407 | int decoded_muted_output; // Number of calls returning a muted state output. |
wu@webrtc.org | 79d6daf | 2013-12-13 19:17:43 | [diff] [blame] | 408 | }; |
| 409 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 410 | // Type of Noise Suppression. |
| 411 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 419 | }; |
| 420 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 421 | // Type of Automatic Gain Control. |
| 422 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 434 | }; |
| 435 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 436 | // Type of Echo Control. |
| 437 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 443 | }; |
| 444 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 445 | // Mode of AECM. |
| 446 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 453 | }; |
| 454 | |
solenberg | cb18650 | 2016-08-31 21:48:53 | [diff] [blame] | 455 | // AGC configuration parameters |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 456 | struct AgcConfig { |
| 457 | unsigned short targetLeveldBOv; |
| 458 | unsigned short digitalCompressionGaindB; |
| 459 | bool limiterEnable; |
solenberg | cb18650 | 2016-08-31 21:48:53 | [diff] [blame] | 460 | }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 461 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 462 | enum StereoChannel { kStereoLeft = 0, kStereoRight, kStereoBoth }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 463 | |
| 464 | // Audio device layers |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 465 | enum AudioLayers { |
| 466 | kAudioPlatformDefault = 0, |
| 467 | kAudioWindowsWave = 1, |
| 468 | kAudioWindowsCore = 2, |
| 469 | kAudioLinuxAlsa = 3, |
| 470 | kAudioLinuxPulse = 4 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 471 | }; |
| 472 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 473 | // ================================================================== |
| 474 | // Video specific types |
| 475 | // ================================================================== |
| 476 | |
| 477 | // Raw video types |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 478 | enum 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | // Video codec |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 497 | enum { kConfigParameterSize = 128 }; |
| 498 | enum { kPayloadNameSize = 32 }; |
| 499 | enum { kMaxSimulcastStreams = 4 }; |
sprang | 0ba16d1 | 2015-11-02 15:23:20 | [diff] [blame] | 500 | enum { kMaxSpatialLayers = 5 }; |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 501 | enum { kMaxTemporalStreams = 4 }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 502 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 503 | enum VideoCodecComplexity { |
| 504 | kComplexityNormal = 0, |
| 505 | kComplexityHigh = 1, |
| 506 | kComplexityHigher = 2, |
| 507 | kComplexityMax = 3 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 508 | }; |
| 509 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 510 | enum 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öm | d146002 | 2016-01-19 15:26:16 | [diff] [blame] | 521 | class TemporalLayersFactory; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 522 | // VP8 specific |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 523 | struct VideoCodecVP8 { |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 524 | bool pictureLossIndicationOn; |
| 525 | bool feedbackModeOn; |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 526 | VideoCodecComplexity complexity; |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 527 | VP8ResilienceMode resilience; |
| 528 | unsigned char numberOfTemporalLayers; |
| 529 | bool denoisingOn; |
| 530 | bool errorConcealmentOn; |
| 531 | bool automaticResizeOn; |
| 532 | bool frameDroppingOn; |
| 533 | int keyFrameInterval; |
Erik Språng | fafcfc0 | 2016-11-16 15:41:30 | [diff] [blame] | 534 | TemporalLayersFactory* tl_factory; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 535 | }; |
| 536 | |
asapersson | 6240797 | 2015-07-31 13:10:09 | [diff] [blame] | 537 | // VP9 specific. |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 538 | struct VideoCodecVP9 { |
| 539 | VideoCodecComplexity complexity; |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 540 | 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.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 549 | }; |
| 550 | |
magjed | b3b56b2 | 2016-11-25 18:06:31 | [diff] [blame] | 551 | // TODO(magjed): Move this and other H264 related classes out to their own file. |
| 552 | namespace H264 { |
| 553 | |
| 554 | enum Profile { |
| 555 | kProfileConstrainedBaseline, |
| 556 | kProfileBaseline, |
| 557 | kProfileMain, |
| 558 | kProfileConstrainedHigh, |
| 559 | kProfileHigh, |
| 560 | }; |
| 561 | |
| 562 | } // namespace H264 |
| 563 | |
stefan@webrtc.org | 2d4a80c | 2014-07-04 12:42:07 | [diff] [blame] | 564 | // H264 specific. |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 565 | struct VideoCodecH264 { |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 566 | bool frameDroppingOn; |
| 567 | int keyFrameInterval; |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 568 | // These are NULL/0 if not externally negotiated. |
| 569 | const uint8_t* spsData; |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 570 | size_t spsLen; |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 571 | const uint8_t* ppsData; |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 572 | size_t ppsLen; |
magjed | b3b56b2 | 2016-11-25 18:06:31 | [diff] [blame] | 573 | H264::Profile profile; |
stefan@webrtc.org | 2d4a80c | 2014-07-04 12:42:07 | [diff] [blame] | 574 | }; |
| 575 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 576 | // Video codec types |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 577 | enum VideoCodecType { |
| 578 | kVideoCodecVP8, |
| 579 | kVideoCodecVP9, |
| 580 | kVideoCodecH264, |
| 581 | kVideoCodecI420, |
| 582 | kVideoCodecRED, |
| 583 | kVideoCodecULPFEC, |
brandtr | 8b00e9b | 2016-11-07 11:03:41 | [diff] [blame] | 584 | kVideoCodecFlexfec, |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 585 | kVideoCodecGeneric, |
| 586 | kVideoCodecUnknown |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 587 | }; |
| 588 | |
Erik Språng | fafcfc0 | 2016-11-16 15:41:30 | [diff] [blame] | 589 | // Translates from name of codec to codec type and vice versa. |
magjed | 3fcf785 | 2016-11-22 18:16:57 | [diff] [blame] | 590 | rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type); |
Erik Språng | fafcfc0 | 2016-11-16 15:41:30 | [diff] [blame] | 591 | rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name); |
| 592 | |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 593 | union VideoCodecUnion { |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 594 | VideoCodecVP8 VP8; |
| 595 | VideoCodecVP9 VP9; |
| 596 | VideoCodecH264 H264; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 597 | }; |
| 598 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 599 | // Simulcast is when the same stream is encoded multiple times with different |
| 600 | // settings such as resolution. |
mallinath@webrtc.org | 18c2945 | 2014-03-21 00:41:28 | [diff] [blame] | 601 | struct SimulcastStream { |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 602 | 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.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 609 | }; |
| 610 | |
sprang | 0ba16d1 | 2015-11-02 15:23:20 | [diff] [blame] | 611 | struct 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 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 618 | enum VideoCodecMode { kRealtimeVideo, kScreensharing }; |
stefan@webrtc.org | f4d3788 | 2013-02-18 14:40:18 | [diff] [blame] | 619 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 620 | // Common video codec properties |
hta | 078cd6c | 2016-10-25 16:05:06 | [diff] [blame] | 621 | class VideoCodec { |
| 622 | public: |
| 623 | VideoCodec(); |
| 624 | |
| 625 | // Public variables. TODO(hta): Make them private with accessors. |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 626 | VideoCodecType codecType; |
| 627 | char plName[kPayloadNameSize]; |
| 628 | unsigned char plType; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 629 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 630 | unsigned short width; |
| 631 | unsigned short height; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 632 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 633 | 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.org | 3d6910c | 2014-03-24 12:36:52 | [diff] [blame] | 637 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 638 | unsigned char maxFramerate; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 639 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 640 | unsigned int qpMax; |
| 641 | unsigned char numberOfSimulcastStreams; |
| 642 | SimulcastStream simulcastStream[kMaxSimulcastStreams]; |
sprang | 0ba16d1 | 2015-11-02 15:23:20 | [diff] [blame] | 643 | SpatialLayer spatialLayers[kMaxSpatialLayers]; |
stefan@webrtc.org | f4d3788 | 2013-02-18 14:40:18 | [diff] [blame] | 644 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 645 | VideoCodecMode mode; |
| 646 | bool expect_encode_from_texture; |
andresp@webrtc.org | ee6f8a2 | 2013-05-14 08:02:25 | [diff] [blame] | 647 | |
Peter Boström | d146002 | 2016-01-19 15:26:16 | [diff] [blame] | 648 | bool operator==(const VideoCodec& other) const = delete; |
| 649 | bool operator!=(const VideoCodec& other) const = delete; |
hta | 078cd6c | 2016-10-25 16:05:06 | [diff] [blame] | 650 | |
| 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 | |
hta | 8ee7814 | 2016-11-17 07:23:04 | [diff] [blame] | 662 | private: |
hta | 078cd6c | 2016-10-25 16:05:06 | [diff] [blame] | 663 | // TODO(hta): Consider replacing the union with a pointer type. |
| 664 | // This will allow removing the VideoCodec* types from this file. |
hta | 8ee7814 | 2016-11-17 07:23:04 | [diff] [blame] | 665 | VideoCodecUnion codec_specific_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 666 | }; |
| 667 | |
Erik Språng | fafcfc0 | 2016-11-16 15:41:30 | [diff] [blame] | 668 | class 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 | |
stefan | 12764bc | 2015-11-27 09:02:31 | [diff] [blame] | 697 | // 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 |
| 700 | struct OverUseDetectorOptions { |
| 701 | OverUseDetectorOptions() |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 702 | : initial_slope(8.0 / 512.0), |
stefan | 12764bc | 2015-11-27 09:02:31 | [diff] [blame] | 703 | 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; |
stefan | 84d41a3 | 2016-03-10 13:13:21 | [diff] [blame] | 712 | initial_process_noise[1] = 1e-3; |
stefan | 12764bc | 2015-11-27 09:02:31 | [diff] [blame] | 713 | } |
| 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.org | efeb8ce | 2013-12-13 00:21:03 | [diff] [blame] | 722 | // This structure will have the information about when packet is actually |
| 723 | // received by socket. |
| 724 | struct PacketTime { |
henrike@webrtc.org | 93ae821 | 2014-04-29 17:50:47 | [diff] [blame] | 725 | PacketTime() : timestamp(-1), not_before(-1) {} |
| 726 | PacketTime(int64_t timestamp, int64_t not_before) |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 727 | : timestamp(timestamp), not_before(not_before) {} |
wu@webrtc.org | efeb8ce | 2013-12-13 00:21:03 | [diff] [blame] | 728 | |
henrike@webrtc.org | 93ae821 | 2014-04-29 17:50:47 | [diff] [blame] | 729 | 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.org | efeb8ce | 2013-12-13 00:21:03 | [diff] [blame] | 735 | }; |
| 736 | |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 737 | // 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. |
| 750 | struct PlayoutDelay { |
| 751 | int min_ms; |
| 752 | int max_ms; |
| 753 | }; |
| 754 | |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 755 | struct RTPHeaderExtension { |
sprang@webrtc.org | 25ec20f | 2015-03-17 14:33:12 | [diff] [blame] | 756 | RTPHeaderExtension(); |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 757 | |
| 758 | bool hasTransmissionTimeOffset; |
| 759 | int32_t transmissionTimeOffset; |
| 760 | bool hasAbsoluteSendTime; |
| 761 | uint32_t absoluteSendTime; |
sprang@webrtc.org | 25ec20f | 2015-03-17 14:33:12 | [diff] [blame] | 762 | bool hasTransportSequenceNumber; |
| 763 | uint16_t transportSequenceNumber; |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 764 | |
| 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; |
Minyue | da4c0f0 | 2015-08-10 13:08:36 | [diff] [blame] | 768 | bool voiceActivity; |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 769 | uint8_t audioLevel; |
guoweis@webrtc.org | 5f74fcf | 2015-03-04 22:55:15 | [diff] [blame] | 770 | |
| 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; |
magjed | 78706f4 | 2016-09-08 10:24:58 | [diff] [blame] | 775 | VideoRotation videoRotation; |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 776 | |
| 777 | PlayoutDelay playout_delay = {-1, -1}; |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 778 | }; |
| 779 | |
| 780 | struct RTPHeader { |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 781 | RTPHeader(); |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 782 | |
| 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.org | 0ab923a | 2014-11-20 22:28:14 | [diff] [blame] | 790 | size_t paddingLength; |
| 791 | size_t headerLength; |
solenberg@webrtc.org | fec6b6e | 2014-03-24 10:38:25 | [diff] [blame] | 792 | int payload_type_frequency; |
| 793 | RTPHeaderExtension extension; |
| 794 | }; |
| 795 | |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 796 | struct RtpPacketCounter { |
| 797 | RtpPacketCounter() |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 798 | : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {} |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 799 | |
| 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ång | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 807 | void Subtract(const RtpPacketCounter& other) { |
kwiberg | c1a5e1b | 2016-11-29 13:30:40 | [diff] [blame] | 808 | RTC_DCHECK_GE(header_bytes, other.header_bytes); |
Erik Språng | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 809 | header_bytes -= other.header_bytes; |
kwiberg | c1a5e1b | 2016-11-29 13:30:40 | [diff] [blame] | 810 | RTC_DCHECK_GE(payload_bytes, other.payload_bytes); |
Erik Språng | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 811 | payload_bytes -= other.payload_bytes; |
kwiberg | c1a5e1b | 2016-11-29 13:30:40 | [diff] [blame] | 812 | RTC_DCHECK_GE(padding_bytes, other.padding_bytes); |
Erik Språng | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 813 | padding_bytes -= other.padding_bytes; |
kwiberg | c1a5e1b | 2016-11-29 13:30:40 | [diff] [blame] | 814 | RTC_DCHECK_GE(packets, other.packets); |
Erik Språng | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 815 | packets -= other.packets; |
| 816 | } |
| 817 | |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 818 | 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. |
| 837 | struct StreamDataCounters { |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 838 | StreamDataCounters(); |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 839 | |
| 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 && |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 845 | (other.first_packet_time_ms < first_packet_time_ms || |
| 846 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 847 | // Use oldest time. |
| 848 | first_packet_time_ms = other.first_packet_time_ms; |
| 849 | } |
| 850 | } |
| 851 | |
Erik Språng | 01cff72 | 2016-03-01 08:40:42 | [diff] [blame] | 852 | 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.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 864 | 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 | |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 876 | int64_t first_packet_time_ms; // Time when first packet is sent/received. |
| 877 | RtpPacketCounter transmitted; // Number of transmitted packets/bytes. |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 878 | RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes. |
solenberg | faa58c6 | 2016-09-01 14:54:53 | [diff] [blame] | 879 | RtpPacketCounter fec; // Number of redundancy packets/bytes. |
asapersson@webrtc.org | 1a8794b | 2015-02-04 08:34:47 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | // Callback, called whenever byte/packet counts have been updated. |
| 883 | class StreamDataCountersCallback { |
| 884 | public: |
| 885 | virtual ~StreamDataCountersCallback() {} |
| 886 | |
| 887 | virtual void DataCountersUpdated(const StreamDataCounters& counters, |
| 888 | uint32_t ssrc) = 0; |
| 889 | }; |
pbos | ba01e95 | 2015-10-02 09:36:56 | [diff] [blame] | 890 | |
| 891 | // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size |
| 892 | // RTCP mode is described by RFC 5506. |
| 893 | enum class RtcpMode { kOff, kCompound, kReducedSize }; |
| 894 | |
pbos | 47a40a3 | 2016-05-02 03:18:34 | [diff] [blame] | 895 | enum NetworkState { |
| 896 | kNetworkUp, |
| 897 | kNetworkDown, |
| 898 | }; |
| 899 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 900 | } // namespace webrtc |
andrew@webrtc.org | 5cf83f4 | 2013-09-09 17:50:10 | [diff] [blame] | 901 | |
| 902 | #endif // WEBRTC_COMMON_TYPES_H_ |