niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
phoglund@webrtc.org | 8bfee84 | 2012-02-17 09:32:48 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 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 | eda189b | 2013-09-09 17:50:10 | [diff] [blame] | 11 | #ifndef WEBRTC_COMMON_TYPES_H_ |
| 12 | #define WEBRTC_COMMON_TYPES_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 13 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 14 | #include <stddef.h> |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 15 | #include <string.h> |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 16 | |
kwiberg | 5bf4e08 | 2016-12-19 14:04:04 | [diff] [blame] | 17 | #include <ostream> |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 | [diff] [blame] | 18 | #include <string> |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
ilnik | 00d802b | 2017-04-11 17:34:31 | [diff] [blame] | 21 | #include "webrtc/api/video/video_content_type.h" |
nisse | af91689 | 2017-01-10 15:44:26 | [diff] [blame] | 22 | #include "webrtc/api/video/video_rotation.h" |
ilnik | 04f4d12 | 2017-06-19 14:18:55 | [diff] [blame] | 23 | #include "webrtc/api/video/video_timing.h" |
Henrik Kjellander | a80c16a | 2017-07-01 14:48:15 | [diff] [blame] | 24 | #include "webrtc/base/array_view.h" |
| 25 | #include "webrtc/base/checks.h" |
| 26 | #include "webrtc/base/optional.h" |
andrew@webrtc.org | eda189b | 2013-09-09 17:50:10 | [diff] [blame] | 27 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 28 | |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 29 | #if defined(_MSC_VER) |
| 30 | // Disable "new behavior: elements of array will be default initialized" |
| 31 | // warning. Affects OverUseDetectorOptions. |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 32 | #pragma warning(disable : 4351) |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 33 | #endif |
| 34 | |
kwiberg | 77eab70 | 2016-09-29 00:42:01 | [diff] [blame] | 35 | #if defined(WEBRTC_EXPORT) |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 36 | #define WEBRTC_DLLEXPORT _declspec(dllexport) |
kwiberg | 77eab70 | 2016-09-29 00:42:01 | [diff] [blame] | 37 | #elif defined(WEBRTC_DLL) |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 38 | #define WEBRTC_DLLEXPORT _declspec(dllimport) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 39 | #else |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 40 | #define WEBRTC_DLLEXPORT |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | #ifndef NULL |
andrew@webrtc.org | 88b8b0d | 2012-08-14 00:05:56 | [diff] [blame] | 44 | #define NULL 0 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 45 | #endif |
| 46 | |
Peter Boström | 8b79b07 | 2016-02-26 15:31:37 | [diff] [blame] | 47 | #define RTP_PAYLOAD_NAME_SIZE 32u |
henrika@webrtc.org | f75901f | 2012-01-16 08:45:42 | [diff] [blame] | 48 | |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 49 | #if defined(WEBRTC_WIN) || defined(WIN32) |
andrew@webrtc.org | eda189b | 2013-09-09 17:50:10 | [diff] [blame] | 50 | // Compares two strings without regard to case. |
| 51 | #define STR_CASE_CMP(s1, s2) ::_stricmp(s1, s2) |
| 52 | // Compares characters of two strings without regard to case. |
| 53 | #define STR_NCASE_CMP(s1, s2, n) ::_strnicmp(s1, s2, n) |
| 54 | #else |
| 55 | #define STR_CASE_CMP(s1, s2) ::strcasecmp(s1, s2) |
| 56 | #define STR_NCASE_CMP(s1, s2, n) ::strncasecmp(s1, s2, n) |
| 57 | #endif |
| 58 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 59 | namespace webrtc { |
| 60 | |
tommi | a6219cc | 2016-06-15 17:30:14 | [diff] [blame] | 61 | class RewindableStream { |
| 62 | public: |
| 63 | virtual ~RewindableStream() {} |
| 64 | virtual int Rewind() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 65 | }; |
| 66 | |
tommi | a6219cc | 2016-06-15 17:30:14 | [diff] [blame] | 67 | class InStream : public RewindableStream { |
| 68 | public: |
| 69 | // Reads |len| bytes from file to |buf|. Returns the number of bytes read |
| 70 | // or -1 on error. |
| 71 | virtual int Read(void* buf, size_t len) = 0; |
| 72 | }; |
| 73 | |
| 74 | class OutStream : public RewindableStream { |
| 75 | public: |
| 76 | // Writes |len| bytes from |buf| to file. The actual writing may happen |
| 77 | // some time later. Call Flush() to force a write. |
| 78 | virtual bool Write(const void* buf, size_t len) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 79 | }; |
| 80 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 81 | enum TraceModule { |
| 82 | kTraceUndefined = 0, |
| 83 | // not a module, triggered from the engine code |
| 84 | kTraceVoice = 0x0001, |
| 85 | // not a module, triggered from the engine code |
| 86 | kTraceVideo = 0x0002, |
| 87 | // not a module, triggered from the utility code |
| 88 | 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, |
| 102 | kTraceRemoteBitrateEstimator = 0x0017, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 103 | }; |
| 104 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 105 | enum TraceLevel { |
| 106 | kTraceNone = 0x0000, // no trace |
| 107 | kTraceStateInfo = 0x0001, |
| 108 | kTraceWarning = 0x0002, |
| 109 | kTraceError = 0x0004, |
| 110 | kTraceCritical = 0x0008, |
| 111 | kTraceApiCall = 0x0010, |
| 112 | kTraceDefault = 0x00ff, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 113 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 114 | kTraceModuleCall = 0x0020, |
| 115 | kTraceMemory = 0x0100, // memory info |
| 116 | kTraceTimer = 0x0200, // timing info |
| 117 | kTraceStream = 0x0400, // "continuous" stream of data |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 118 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 119 | // used for debug purposes |
| 120 | kTraceDebug = 0x0800, // debug |
| 121 | kTraceInfo = 0x1000, // debug info |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 122 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 123 | // Non-verbose level used by LS_INFO of logging.h. Do not use directly. |
| 124 | kTraceTerseInfo = 0x2000, |
andrew@webrtc.org | 655d8f5 | 2012-11-20 07:34:45 | [diff] [blame] | 125 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 126 | kTraceAll = 0xffff |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | // External Trace API |
andrew@webrtc.org | 23ec30b | 2012-11-15 05:33:25 | [diff] [blame] | 130 | class TraceCallback { |
| 131 | public: |
| 132 | virtual void Print(TraceLevel level, const char* message, int length) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 133 | |
andrew@webrtc.org | 23ec30b | 2012-11-15 05:33:25 | [diff] [blame] | 134 | protected: |
| 135 | virtual ~TraceCallback() {} |
| 136 | TraceCallback() {} |
| 137 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 138 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 139 | enum FileFormats { |
| 140 | kFileFormatWavFile = 1, |
| 141 | kFileFormatCompressedFile = 2, |
| 142 | kFileFormatPreencodedFile = 4, |
| 143 | kFileFormatPcm16kHzFile = 7, |
| 144 | kFileFormatPcm8kHzFile = 8, |
lliuu | bc436ed | 2017-03-31 23:32:28 | [diff] [blame] | 145 | kFileFormatPcm32kHzFile = 9 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 146 | }; |
| 147 | |
pbos | 22993e1 | 2015-10-19 09:39:06 | [diff] [blame] | 148 | enum FrameType { |
| 149 | kEmptyFrame = 0, |
| 150 | kAudioFrameSpeech = 1, |
| 151 | kAudioFrameCN = 2, |
| 152 | kVideoFrameKey = 3, |
| 153 | kVideoFrameDelta = 4, |
sprang@webrtc.org | 71f055f | 2013-12-04 15:09:27 | [diff] [blame] | 154 | }; |
| 155 | |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 156 | // Statistics for an RTCP channel |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 | [diff] [blame] | 157 | struct RtcpStatistics { |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 | [diff] [blame] | 158 | RtcpStatistics() |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 159 | : fraction_lost(0), |
| 160 | cumulative_lost(0), |
| 161 | extended_max_sequence_number(0), |
| 162 | jitter(0) {} |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 | [diff] [blame] | 163 | |
| 164 | uint8_t fraction_lost; |
| 165 | uint32_t cumulative_lost; |
| 166 | uint32_t extended_max_sequence_number; |
| 167 | uint32_t jitter; |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 | [diff] [blame] | 168 | }; |
| 169 | |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 170 | class RtcpStatisticsCallback { |
| 171 | public: |
| 172 | virtual ~RtcpStatisticsCallback() {} |
| 173 | |
| 174 | virtual void StatisticsUpdated(const RtcpStatistics& statistics, |
| 175 | uint32_t ssrc) = 0; |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 | [diff] [blame] | 176 | virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 177 | }; |
| 178 | |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 | [diff] [blame] | 179 | // Statistics for RTCP packet types. |
| 180 | struct RtcpPacketTypeCounter { |
| 181 | RtcpPacketTypeCounter() |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 182 | : first_packet_time_ms(-1), |
| 183 | nack_packets(0), |
| 184 | fir_packets(0), |
| 185 | pli_packets(0), |
| 186 | nack_requests(0), |
| 187 | unique_nack_requests(0) {} |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 | [diff] [blame] | 188 | |
| 189 | void Add(const RtcpPacketTypeCounter& other) { |
| 190 | nack_packets += other.nack_packets; |
| 191 | fir_packets += other.fir_packets; |
| 192 | pli_packets += other.pli_packets; |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 | [diff] [blame] | 193 | nack_requests += other.nack_requests; |
| 194 | unique_nack_requests += other.unique_nack_requests; |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 | [diff] [blame] | 195 | if (other.first_packet_time_ms != -1 && |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 196 | (other.first_packet_time_ms < first_packet_time_ms || |
| 197 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 | [diff] [blame] | 198 | // Use oldest time. |
| 199 | first_packet_time_ms = other.first_packet_time_ms; |
| 200 | } |
| 201 | } |
| 202 | |
sprang | 07fb9be | 2016-02-24 15:55:00 | [diff] [blame] | 203 | void Subtract(const RtcpPacketTypeCounter& other) { |
| 204 | nack_packets -= other.nack_packets; |
| 205 | fir_packets -= other.fir_packets; |
| 206 | pli_packets -= other.pli_packets; |
| 207 | nack_requests -= other.nack_requests; |
| 208 | unique_nack_requests -= other.unique_nack_requests; |
| 209 | if (other.first_packet_time_ms != -1 && |
| 210 | (other.first_packet_time_ms > first_packet_time_ms || |
| 211 | first_packet_time_ms == -1)) { |
| 212 | // Use youngest time. |
| 213 | first_packet_time_ms = other.first_packet_time_ms; |
| 214 | } |
| 215 | } |
| 216 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 | [diff] [blame] | 217 | int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { |
| 218 | return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms); |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 | [diff] [blame] | 219 | } |
| 220 | |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 | [diff] [blame] | 221 | int UniqueNackRequestsInPercent() const { |
| 222 | if (nack_requests == 0) { |
| 223 | return 0; |
| 224 | } |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 225 | return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) + |
| 226 | 0.5f); |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 | [diff] [blame] | 227 | } |
| 228 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 229 | int64_t first_packet_time_ms; // Time when first packet is sent/received. |
| 230 | uint32_t nack_packets; // Number of RTCP NACK packets. |
| 231 | uint32_t fir_packets; // Number of RTCP FIR packets. |
| 232 | uint32_t pli_packets; // Number of RTCP PLI packets. |
| 233 | uint32_t nack_requests; // Number of NACKed RTP packets. |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 | [diff] [blame] | 234 | uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 | [diff] [blame] | 235 | }; |
| 236 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 | [diff] [blame] | 237 | class RtcpPacketTypeCounterObserver { |
| 238 | public: |
| 239 | virtual ~RtcpPacketTypeCounterObserver() {} |
| 240 | virtual void RtcpPacketTypesCounterUpdated( |
| 241 | uint32_t ssrc, |
| 242 | const RtcpPacketTypeCounter& packet_counter) = 0; |
| 243 | }; |
| 244 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 | [diff] [blame] | 245 | // Rate statistics for a stream. |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 246 | struct BitrateStatistics { |
sprang | cd349d9 | 2016-07-13 16:11:28 | [diff] [blame] | 247 | BitrateStatistics() : bitrate_bps(0), packet_rate(0) {} |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 248 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 249 | uint32_t bitrate_bps; // Bitrate in bits per second. |
| 250 | uint32_t packet_rate; // Packet rate in packets per second. |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | // Callback, used to notify an observer whenever new rates have been estimated. |
| 254 | class BitrateStatisticsObserver { |
| 255 | public: |
| 256 | virtual ~BitrateStatisticsObserver() {} |
| 257 | |
sprang | cd349d9 | 2016-07-13 16:11:28 | [diff] [blame] | 258 | virtual void Notify(uint32_t total_bitrate_bps, |
| 259 | uint32_t retransmit_bitrate_bps, |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 260 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 261 | }; |
| 262 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 | [diff] [blame] | 263 | struct FrameCounts { |
| 264 | FrameCounts() : key_frames(0), delta_frames(0) {} |
| 265 | int key_frames; |
| 266 | int delta_frames; |
| 267 | }; |
| 268 | |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 | [diff] [blame] | 269 | // Callback, used to notify an observer whenever frame counts have been updated. |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 270 | class FrameCountObserver { |
| 271 | public: |
sprang@webrtc.org | 72964bd | 2013-11-21 09:09:54 | [diff] [blame] | 272 | virtual ~FrameCountObserver() {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 | [diff] [blame] | 273 | virtual void FrameCountUpdated(const FrameCounts& frame_counts, |
| 274 | uint32_t ssrc) = 0; |
sprang@webrtc.org | dc50aae | 2013-11-20 16:47:07 | [diff] [blame] | 275 | }; |
| 276 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 | [diff] [blame] | 277 | // Callback, used to notify an observer whenever the send-side delay is updated. |
| 278 | class SendSideDelayObserver { |
| 279 | public: |
| 280 | virtual ~SendSideDelayObserver() {} |
| 281 | virtual void SendSideDelayUpdated(int avg_delay_ms, |
| 282 | int max_delay_ms, |
| 283 | uint32_t ssrc) = 0; |
| 284 | }; |
| 285 | |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 286 | // Callback, used to notify an observer whenever a packet is sent to the |
| 287 | // transport. |
| 288 | // TODO(asapersson): This class will remove the need for SendSideDelayObserver. |
| 289 | // Remove SendSideDelayObserver once possible. |
| 290 | class SendPacketObserver { |
| 291 | public: |
| 292 | virtual ~SendPacketObserver() {} |
| 293 | virtual void OnSendPacket(uint16_t packet_id, |
| 294 | int64_t capture_time_ms, |
| 295 | uint32_t ssrc) = 0; |
| 296 | }; |
| 297 | |
michaelt | 4da3044 | 2016-11-17 09:38:43 | [diff] [blame] | 298 | // Callback, used to notify an observer when the overhead per packet |
| 299 | // has changed. |
| 300 | class OverheadObserver { |
| 301 | public: |
| 302 | virtual ~OverheadObserver() = default; |
| 303 | virtual void OnOverheadChanged(size_t overhead_bytes_per_packet) = 0; |
| 304 | }; |
| 305 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 306 | // ================================================================== |
| 307 | // Voice specific types |
| 308 | // ================================================================== |
| 309 | |
| 310 | // Each codec supported can be described by this structure. |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 311 | struct CodecInst { |
| 312 | int pltype; |
| 313 | char plname[RTP_PAYLOAD_NAME_SIZE]; |
| 314 | int plfreq; |
| 315 | int pacsize; |
Peter Kasting | 6955870 | 2016-01-13 00:26:35 | [diff] [blame] | 316 | size_t channels; |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 317 | 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) && |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 322 | plfreq == other.plfreq && pacsize == other.pacsize && |
| 323 | channels == other.channels && rate == other.rate; |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 324 | } |
| 325 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 326 | bool operator!=(const CodecInst& other) const { return !(*this == other); } |
kwiberg | 5bf4e08 | 2016-12-19 14:04:04 | [diff] [blame] | 327 | |
| 328 | friend std::ostream& operator<<(std::ostream& os, const CodecInst& ci) { |
| 329 | os << "{pltype: " << ci.pltype; |
| 330 | os << ", plname: " << ci.plname; |
| 331 | os << ", plfreq: " << ci.plfreq; |
| 332 | os << ", pacsize: " << ci.pacsize; |
| 333 | os << ", channels: " << ci.channels; |
| 334 | os << ", rate: " << ci.rate << "}"; |
| 335 | return os; |
| 336 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 337 | }; |
| 338 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 339 | // RTP |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 340 | enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 341 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 342 | enum PayloadFrequencies { |
| 343 | kFreq8000Hz = 8000, |
| 344 | kFreq16000Hz = 16000, |
| 345 | kFreq32000Hz = 32000 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 346 | }; |
| 347 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 348 | // Degree of bandwidth reduction. |
| 349 | enum VadModes { |
| 350 | kVadConventional = 0, // lowest reduction |
| 351 | kVadAggressiveLow, |
| 352 | kVadAggressiveMid, |
| 353 | kVadAggressiveHigh // highest reduction |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 354 | }; |
| 355 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 356 | // NETEQ statistics. |
| 357 | struct NetworkStatistics { |
| 358 | // current jitter buffer size in ms |
| 359 | uint16_t currentBufferSize; |
| 360 | // preferred (optimal) buffer size in ms |
| 361 | uint16_t preferredBufferSize; |
| 362 | // adding extra delay due to "peaky jitter" |
| 363 | bool jitterPeaksFound; |
| 364 | // Loss rate (network + late); fraction between 0 and 1, scaled to Q14. |
| 365 | uint16_t currentPacketLossRate; |
| 366 | // Late loss rate; fraction between 0 and 1, scaled to Q14. |
| 367 | uint16_t currentDiscardRate; |
| 368 | // fraction (of original stream) of synthesized audio inserted through |
| 369 | // expansion (in Q14) |
| 370 | uint16_t currentExpandRate; |
| 371 | // fraction (of original stream) of synthesized speech inserted through |
| 372 | // expansion (in Q14) |
| 373 | uint16_t currentSpeechExpandRate; |
| 374 | // fraction of synthesized speech inserted through pre-emptive expansion |
| 375 | // (in Q14) |
| 376 | uint16_t currentPreemptiveRate; |
| 377 | // fraction of data removed through acceleration (in Q14) |
| 378 | uint16_t currentAccelerateRate; |
| 379 | // fraction of data coming from secondary decoding (in Q14) |
| 380 | uint16_t currentSecondaryDecodedRate; |
| 381 | // clock-drift in parts-per-million (negative or positive) |
| 382 | int32_t clockDriftPPM; |
| 383 | // average packet waiting time in the jitter buffer (ms) |
| 384 | int meanWaitingTimeMs; |
| 385 | // median packet waiting time in the jitter buffer (ms) |
| 386 | int medianWaitingTimeMs; |
| 387 | // min packet waiting time in the jitter buffer (ms) |
| 388 | int minWaitingTimeMs; |
| 389 | // max packet waiting time in the jitter buffer (ms) |
| 390 | int maxWaitingTimeMs; |
| 391 | // added samples in off mode due to packet loss |
| 392 | size_t addedSamples; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 393 | }; |
| 394 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 | [diff] [blame] | 395 | // Statistics for calls to AudioCodingModule::PlayoutData10Ms(). |
| 396 | struct AudioDecodingCallStats { |
| 397 | AudioDecodingCallStats() |
| 398 | : calls_to_silence_generator(0), |
| 399 | calls_to_neteq(0), |
| 400 | decoded_normal(0), |
| 401 | decoded_plc(0), |
| 402 | decoded_cng(0), |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 403 | decoded_plc_cng(0), |
| 404 | decoded_muted_output(0) {} |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 | [diff] [blame] | 405 | |
| 406 | int calls_to_silence_generator; // Number of calls where silence generated, |
| 407 | // and NetEq was disengaged from decoding. |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 408 | int calls_to_neteq; // Number of calls to NetEq. |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 | [diff] [blame] | 409 | int decoded_normal; // Number of calls where audio RTP packet decoded. |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 410 | int decoded_plc; // Number of calls resulted in PLC. |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 | [diff] [blame] | 411 | int decoded_cng; // Number of calls where comfort noise generated due to DTX. |
| 412 | int decoded_plc_cng; // Number of calls resulted where PLC faded to CNG. |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 413 | int decoded_muted_output; // Number of calls returning a muted state output. |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 | [diff] [blame] | 414 | }; |
| 415 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 416 | // ================================================================== |
| 417 | // Video specific types |
| 418 | // ================================================================== |
| 419 | |
nisse | eb44b39 | 2017-04-28 14:18:05 | [diff] [blame] | 420 | // TODO(nisse): Delete, and switch to fourcc values everywhere? |
| 421 | // Supported video types. |
| 422 | enum class VideoType { |
| 423 | kUnknown, |
| 424 | kI420, |
| 425 | kIYUV, |
| 426 | kRGB24, |
| 427 | kABGR, |
| 428 | kARGB, |
| 429 | kARGB4444, |
| 430 | kRGB565, |
| 431 | kARGB1555, |
| 432 | kYUY2, |
| 433 | kYV12, |
| 434 | kUYVY, |
| 435 | kMJPEG, |
| 436 | kNV21, |
| 437 | kNV12, |
| 438 | kBGRA, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | // Video codec |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 442 | enum { kPayloadNameSize = 32 }; |
| 443 | enum { kMaxSimulcastStreams = 4 }; |
sprang | ce4aef1 | 2015-11-02 15:23:20 | [diff] [blame] | 444 | enum { kMaxSpatialLayers = 5 }; |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 445 | enum { kMaxTemporalStreams = 4 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 446 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 447 | enum VideoCodecComplexity { |
| 448 | kComplexityNormal = 0, |
| 449 | kComplexityHigh = 1, |
| 450 | kComplexityHigher = 2, |
| 451 | kComplexityMax = 3 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 452 | }; |
| 453 | |
stefan@webrtc.org | efd0a48 | 2011-12-29 10:12:35 | [diff] [blame] | 454 | enum VP8ResilienceMode { |
| 455 | kResilienceOff, // The stream produced by the encoder requires a |
| 456 | // recovery frame (typically a key frame) to be |
| 457 | // decodable after a packet loss. |
| 458 | kResilientStream, // A stream produced by the encoder is resilient to |
| 459 | // packet losses, but packets within a frame subsequent |
| 460 | // to a loss can't be decoded. |
| 461 | kResilientFrames // Same as kResilientStream but with added resilience |
| 462 | // within a frame. |
| 463 | }; |
| 464 | |
Peter Boström | 7b971e7 | 2016-01-19 15:26:16 | [diff] [blame] | 465 | class TemporalLayersFactory; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 466 | // VP8 specific |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 467 | struct VideoCodecVP8 { |
nisse | 3257b16 | 2017-03-21 08:54:13 | [diff] [blame] | 468 | // TODO(nisse): Unused, delete? |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 469 | bool pictureLossIndicationOn; |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 470 | VideoCodecComplexity complexity; |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 471 | VP8ResilienceMode resilience; |
| 472 | unsigned char numberOfTemporalLayers; |
| 473 | bool denoisingOn; |
| 474 | bool errorConcealmentOn; |
| 475 | bool automaticResizeOn; |
| 476 | bool frameDroppingOn; |
| 477 | int keyFrameInterval; |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 478 | TemporalLayersFactory* tl_factory; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 479 | }; |
| 480 | |
asapersson | a9455ab | 2015-07-31 13:10:09 | [diff] [blame] | 481 | // VP9 specific. |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 482 | struct VideoCodecVP9 { |
| 483 | VideoCodecComplexity complexity; |
asapersson | 15dcb38 | 2017-06-08 09:55:08 | [diff] [blame] | 484 | bool resilienceOn; |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 485 | unsigned char numberOfTemporalLayers; |
| 486 | bool denoisingOn; |
| 487 | bool frameDroppingOn; |
| 488 | int keyFrameInterval; |
| 489 | bool adaptiveQpMode; |
| 490 | bool automaticResizeOn; |
| 491 | unsigned char numberOfSpatialLayers; |
| 492 | bool flexibleMode; |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 493 | }; |
| 494 | |
magjed | e69a1a9 | 2016-11-25 18:06:31 | [diff] [blame] | 495 | // TODO(magjed): Move this and other H264 related classes out to their own file. |
| 496 | namespace H264 { |
| 497 | |
| 498 | enum Profile { |
| 499 | kProfileConstrainedBaseline, |
| 500 | kProfileBaseline, |
| 501 | kProfileMain, |
| 502 | kProfileConstrainedHigh, |
| 503 | kProfileHigh, |
| 504 | }; |
| 505 | |
| 506 | } // namespace H264 |
| 507 | |
stefan@webrtc.org | b9f5453 | 2014-07-04 12:42:07 | [diff] [blame] | 508 | // H264 specific. |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 509 | struct VideoCodecH264 { |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 510 | bool frameDroppingOn; |
| 511 | int keyFrameInterval; |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 512 | // These are NULL/0 if not externally negotiated. |
| 513 | const uint8_t* spsData; |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 514 | size_t spsLen; |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 515 | const uint8_t* ppsData; |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 516 | size_t ppsLen; |
magjed | e69a1a9 | 2016-11-25 18:06:31 | [diff] [blame] | 517 | H264::Profile profile; |
stefan@webrtc.org | b9f5453 | 2014-07-04 12:42:07 | [diff] [blame] | 518 | }; |
| 519 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 520 | // Video codec types |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 521 | enum VideoCodecType { |
| 522 | kVideoCodecVP8, |
| 523 | kVideoCodecVP9, |
| 524 | kVideoCodecH264, |
| 525 | kVideoCodecI420, |
| 526 | kVideoCodecRED, |
| 527 | kVideoCodecULPFEC, |
brandtr | 87d7d77 | 2016-11-07 11:03:41 | [diff] [blame] | 528 | kVideoCodecFlexfec, |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 529 | kVideoCodecGeneric, |
| 530 | kVideoCodecUnknown |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 531 | }; |
| 532 | |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 533 | // Translates from name of codec to codec type and vice versa. |
magjed | 10165ab | 2016-11-22 18:16:57 | [diff] [blame] | 534 | rtc::Optional<const char*> CodecTypeToPayloadName(VideoCodecType type); |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 535 | rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name); |
| 536 | |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 537 | union VideoCodecUnion { |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 538 | VideoCodecVP8 VP8; |
| 539 | VideoCodecVP9 VP9; |
| 540 | VideoCodecH264 H264; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 541 | }; |
| 542 | |
phoglund@webrtc.org | 8bfee84 | 2012-02-17 09:32:48 | [diff] [blame] | 543 | // Simulcast is when the same stream is encoded multiple times with different |
| 544 | // settings such as resolution. |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 | [diff] [blame] | 545 | struct SimulcastStream { |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 546 | unsigned short width; |
| 547 | unsigned short height; |
| 548 | unsigned char numberOfTemporalLayers; |
| 549 | unsigned int maxBitrate; // kilobits/sec. |
| 550 | unsigned int targetBitrate; // kilobits/sec. |
| 551 | unsigned int minBitrate; // kilobits/sec. |
| 552 | unsigned int qpMax; // minimum quality |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 | [diff] [blame] | 553 | }; |
| 554 | |
sprang | ce4aef1 | 2015-11-02 15:23:20 | [diff] [blame] | 555 | struct SpatialLayer { |
| 556 | int scaling_factor_num; |
| 557 | int scaling_factor_den; |
| 558 | int target_bitrate_bps; |
| 559 | // TODO(ivica): Add max_quantizer and min_quantizer? |
| 560 | }; |
| 561 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 562 | enum VideoCodecMode { kRealtimeVideo, kScreensharing }; |
stefan@webrtc.org | eb91792 | 2013-02-18 14:40:18 | [diff] [blame] | 563 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 564 | // Common video codec properties |
hta | 257dc39 | 2016-10-25 16:05:06 | [diff] [blame] | 565 | class VideoCodec { |
| 566 | public: |
| 567 | VideoCodec(); |
| 568 | |
| 569 | // Public variables. TODO(hta): Make them private with accessors. |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 570 | VideoCodecType codecType; |
| 571 | char plName[kPayloadNameSize]; |
| 572 | unsigned char plType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 573 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 574 | unsigned short width; |
| 575 | unsigned short height; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 576 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 577 | unsigned int startBitrate; // kilobits/sec. |
| 578 | unsigned int maxBitrate; // kilobits/sec. |
| 579 | unsigned int minBitrate; // kilobits/sec. |
| 580 | unsigned int targetBitrate; // kilobits/sec. |
pbos@webrtc.org | 3c412b2 | 2014-03-24 12:36:52 | [diff] [blame] | 581 | |
Stefan Holmer | 144475b | 2017-03-10 14:08:26 | [diff] [blame] | 582 | uint32_t maxFramerate; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 583 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 584 | unsigned int qpMax; |
| 585 | unsigned char numberOfSimulcastStreams; |
| 586 | SimulcastStream simulcastStream[kMaxSimulcastStreams]; |
sprang | ce4aef1 | 2015-11-02 15:23:20 | [diff] [blame] | 587 | SpatialLayer spatialLayers[kMaxSpatialLayers]; |
stefan@webrtc.org | eb91792 | 2013-02-18 14:40:18 | [diff] [blame] | 588 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 589 | VideoCodecMode mode; |
| 590 | bool expect_encode_from_texture; |
andresp@webrtc.org | 185bae4 | 2013-05-14 08:02:25 | [diff] [blame] | 591 | |
ilnik | 04f4d12 | 2017-06-19 14:18:55 | [diff] [blame] | 592 | // Timing frames configuration. There is delay of delay_ms between two |
| 593 | // consequent timing frames, excluding outliers. Frame is always made a |
| 594 | // timing frame if it's at least outlier_ratio in percent of "ideal" average |
| 595 | // frame given bitrate and framerate, i.e. if it's bigger than |
| 596 | // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing |
| 597 | // frames will not be sent too often usually. Yet large frames will always |
| 598 | // have timing information for debug purposes because they are more likely to |
| 599 | // cause extra delays. |
| 600 | struct TimingFrameTriggerThresholds { |
| 601 | int64_t delay_ms; |
| 602 | uint16_t outlier_ratio_percent; |
| 603 | } timing_frame_thresholds; |
| 604 | |
Peter Boström | 7b971e7 | 2016-01-19 15:26:16 | [diff] [blame] | 605 | bool operator==(const VideoCodec& other) const = delete; |
| 606 | bool operator!=(const VideoCodec& other) const = delete; |
hta | 257dc39 | 2016-10-25 16:05:06 | [diff] [blame] | 607 | |
| 608 | // Accessors for codec specific information. |
| 609 | // There is a const version of each that returns a reference, |
| 610 | // and a non-const version that returns a pointer, in order |
| 611 | // to allow modification of the parameters. |
| 612 | VideoCodecVP8* VP8(); |
| 613 | const VideoCodecVP8& VP8() const; |
| 614 | VideoCodecVP9* VP9(); |
| 615 | const VideoCodecVP9& VP9() const; |
| 616 | VideoCodecH264* H264(); |
| 617 | const VideoCodecH264& H264() const; |
| 618 | |
hta | 527d347 | 2016-11-17 07:23:04 | [diff] [blame] | 619 | private: |
hta | 257dc39 | 2016-10-25 16:05:06 | [diff] [blame] | 620 | // TODO(hta): Consider replacing the union with a pointer type. |
| 621 | // This will allow removing the VideoCodec* types from this file. |
hta | 527d347 | 2016-11-17 07:23:04 | [diff] [blame] | 622 | VideoCodecUnion codec_specific_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 623 | }; |
astor@webrtc.org | bd7aeba | 2012-06-26 10:47:04 | [diff] [blame] | 624 | |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 625 | class BitrateAllocation { |
| 626 | public: |
| 627 | static const uint32_t kMaxBitrateBps; |
| 628 | BitrateAllocation(); |
| 629 | |
| 630 | bool SetBitrate(size_t spatial_index, |
| 631 | size_t temporal_index, |
| 632 | uint32_t bitrate_bps); |
| 633 | |
| 634 | uint32_t GetBitrate(size_t spatial_index, size_t temporal_index) const; |
| 635 | |
| 636 | // Get the sum of all the temporal layer for a specific spatial layer. |
| 637 | uint32_t GetSpatialLayerSum(size_t spatial_index) const; |
| 638 | |
| 639 | uint32_t get_sum_bps() const { return sum_; } // Sum of all bitrates. |
| 640 | uint32_t get_sum_kbps() const { return (sum_ + 500) / 1000; } |
| 641 | |
| 642 | inline bool operator==(const BitrateAllocation& other) const { |
| 643 | return memcmp(bitrates_, other.bitrates_, sizeof(bitrates_)) == 0; |
| 644 | } |
| 645 | inline bool operator!=(const BitrateAllocation& other) const { |
| 646 | return !(*this == other); |
| 647 | } |
| 648 | |
sprang | d0fc37a | 2017-06-22 12:40:25 | [diff] [blame] | 649 | // Expensive, please use only in tests. |
| 650 | std::string ToString() const; |
| 651 | std::ostream& operator<<(std::ostream& os) const; |
| 652 | |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 653 | private: |
| 654 | uint32_t sum_; |
| 655 | uint32_t bitrates_[kMaxSpatialLayers][kMaxTemporalStreams]; |
| 656 | }; |
| 657 | |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 658 | // Bandwidth over-use detector options. These are used to drive |
| 659 | // experimentation with bandwidth estimation parameters. |
| 660 | // See modules/remote_bitrate_estimator/overuse_detector.h |
terelius | 84f83f8 | 2016-12-27 18:43:01 | [diff] [blame] | 661 | // TODO(terelius): This is only used in overuse_estimator.cc, and only in the |
| 662 | // default constructed state. Can we move the relevant variables into that |
| 663 | // class and delete this? See also disabled warning at line 27 |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 664 | struct OverUseDetectorOptions { |
| 665 | OverUseDetectorOptions() |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 666 | : initial_slope(8.0 / 512.0), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 667 | initial_offset(0), |
| 668 | initial_e(), |
| 669 | initial_process_noise(), |
| 670 | initial_avg_noise(0.0), |
| 671 | initial_var_noise(50) { |
| 672 | initial_e[0][0] = 100; |
| 673 | initial_e[1][1] = 1e-1; |
| 674 | initial_e[0][1] = initial_e[1][0] = 0; |
| 675 | initial_process_noise[0] = 1e-13; |
stefan | 1069cac | 2016-03-10 13:13:21 | [diff] [blame] | 676 | initial_process_noise[1] = 1e-3; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 677 | } |
| 678 | double initial_slope; |
| 679 | double initial_offset; |
| 680 | double initial_e[2][2]; |
| 681 | double initial_process_noise[2]; |
| 682 | double initial_avg_noise; |
| 683 | double initial_var_noise; |
| 684 | }; |
| 685 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 686 | // This structure will have the information about when packet is actually |
| 687 | // received by socket. |
| 688 | struct PacketTime { |
henrike@webrtc.org | 82d3cb6 | 2014-04-29 17:50:47 | [diff] [blame] | 689 | PacketTime() : timestamp(-1), not_before(-1) {} |
| 690 | PacketTime(int64_t timestamp, int64_t not_before) |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 691 | : timestamp(timestamp), not_before(not_before) {} |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 692 | |
henrike@webrtc.org | 82d3cb6 | 2014-04-29 17:50:47 | [diff] [blame] | 693 | int64_t timestamp; // Receive time after socket delivers the data. |
| 694 | int64_t not_before; // Earliest possible time the data could have arrived, |
| 695 | // indicating the potential error in the |timestamp| |
| 696 | // value,in case the system is busy. |
| 697 | // For example, the time of the last select() call. |
| 698 | // If unknown, this value will be set to zero. |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 699 | }; |
| 700 | |
isheriff | 6b4b5f3 | 2016-06-08 07:24:21 | [diff] [blame] | 701 | // Minimum and maximum playout delay values from capture to render. |
| 702 | // These are best effort values. |
| 703 | // |
| 704 | // A value < 0 indicates no change from previous valid value. |
| 705 | // |
| 706 | // min = max = 0 indicates that the receiver should try and render |
| 707 | // frame as soon as possible. |
| 708 | // |
| 709 | // min = x, max = y indicates that the receiver is free to adapt |
| 710 | // in the range (x, y) based on network jitter. |
| 711 | // |
| 712 | // Note: Given that this gets embedded in a union, it is up-to the owner to |
| 713 | // initialize these values. |
| 714 | struct PlayoutDelay { |
| 715 | int min_ms; |
| 716 | int max_ms; |
| 717 | }; |
| 718 | |
danilchap | ef8d773 | 2017-04-19 09:59:48 | [diff] [blame] | 719 | // Class to represent RtpStreamId which is a string. |
| 720 | // Unlike std::string, it can be copied with memcpy and cleared with memset. |
| 721 | // Empty value represent unset RtpStreamId. |
| 722 | class StreamId { |
| 723 | public: |
| 724 | // Stream id is limited to 16 bytes because it is the maximum length |
| 725 | // that can be encoded with one-byte header extensions. |
| 726 | static constexpr size_t kMaxSize = 16; |
| 727 | |
eladalon | d0244c2 | 2017-06-08 11:19:13 | [diff] [blame] | 728 | static bool IsLegalName(rtc::ArrayView<const char> name); |
| 729 | |
danilchap | ef8d773 | 2017-04-19 09:59:48 | [diff] [blame] | 730 | StreamId() { value_[0] = 0; } |
| 731 | explicit StreamId(rtc::ArrayView<const char> value) { |
| 732 | Set(value.data(), value.size()); |
| 733 | } |
| 734 | StreamId(const StreamId&) = default; |
| 735 | StreamId& operator=(const StreamId&) = default; |
| 736 | |
| 737 | bool empty() const { return value_[0] == 0; } |
| 738 | const char* data() const { return value_; } |
| 739 | size_t size() const { return strnlen(value_, kMaxSize); } |
| 740 | |
| 741 | void Set(rtc::ArrayView<const uint8_t> value) { |
| 742 | Set(reinterpret_cast<const char*>(value.data()), value.size()); |
| 743 | } |
| 744 | void Set(const char* data, size_t size); |
| 745 | |
| 746 | friend bool operator==(const StreamId& lhs, const StreamId& rhs) { |
| 747 | return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0; |
| 748 | } |
| 749 | friend bool operator!=(const StreamId& lhs, const StreamId& rhs) { |
| 750 | return !(lhs == rhs); |
| 751 | } |
| 752 | |
| 753 | private: |
| 754 | char value_[kMaxSize]; |
| 755 | }; |
| 756 | |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 757 | struct RTPHeaderExtension { |
sprang@webrtc.org | 3093390 | 2015-03-17 14:33:12 | [diff] [blame] | 758 | RTPHeaderExtension(); |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 759 | |
| 760 | bool hasTransmissionTimeOffset; |
| 761 | int32_t transmissionTimeOffset; |
| 762 | bool hasAbsoluteSendTime; |
| 763 | uint32_t absoluteSendTime; |
sprang@webrtc.org | 3093390 | 2015-03-17 14:33:12 | [diff] [blame] | 764 | bool hasTransportSequenceNumber; |
| 765 | uint16_t transportSequenceNumber; |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 766 | |
| 767 | // Audio Level includes both level in dBov and voiced/unvoiced bit. See: |
| 768 | // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/ |
| 769 | bool hasAudioLevel; |
Minyue | 4cee419 | 2015-08-10 13:08:36 | [diff] [blame] | 770 | bool voiceActivity; |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 771 | uint8_t audioLevel; |
guoweis@webrtc.org | 4536289 | 2015-03-04 22:55:15 | [diff] [blame] | 772 | |
| 773 | // For Coordination of Video Orientation. See |
| 774 | // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
| 775 | // ts_126114v120700p.pdf |
| 776 | bool hasVideoRotation; |
magjed | 71eb61c | 2016-09-08 10:24:58 | [diff] [blame] | 777 | VideoRotation videoRotation; |
isheriff | 6b4b5f3 | 2016-06-08 07:24:21 | [diff] [blame] | 778 | |
ilnik | 00d802b | 2017-04-11 17:34:31 | [diff] [blame] | 779 | // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove |
| 780 | // a corresponding bool flag. |
| 781 | bool hasVideoContentType; |
| 782 | VideoContentType videoContentType; |
| 783 | |
ilnik | 04f4d12 | 2017-06-19 14:18:55 | [diff] [blame] | 784 | bool has_video_timing; |
| 785 | VideoTiming video_timing; |
| 786 | |
isheriff | 6b4b5f3 | 2016-06-08 07:24:21 | [diff] [blame] | 787 | PlayoutDelay playout_delay = {-1, -1}; |
danilchap | ef8d773 | 2017-04-19 09:59:48 | [diff] [blame] | 788 | |
| 789 | // For identification of a stream when ssrc is not signaled. See |
| 790 | // https://tools.ietf.org/html/draft-ietf-avtext-rid-09 |
| 791 | // TODO(danilchap): Update url from draft to release version. |
| 792 | StreamId stream_id; |
| 793 | StreamId repaired_stream_id; |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | struct RTPHeader { |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 | [diff] [blame] | 797 | RTPHeader(); |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 798 | |
| 799 | bool markerBit; |
| 800 | uint8_t payloadType; |
| 801 | uint16_t sequenceNumber; |
| 802 | uint32_t timestamp; |
| 803 | uint32_t ssrc; |
| 804 | uint8_t numCSRCs; |
| 805 | uint32_t arrOfCSRCs[kRtpCsrcSize]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 806 | size_t paddingLength; |
| 807 | size_t headerLength; |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 | [diff] [blame] | 808 | int payload_type_frequency; |
| 809 | RTPHeaderExtension extension; |
| 810 | }; |
| 811 | |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 812 | struct RtpPacketCounter { |
| 813 | RtpPacketCounter() |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 814 | : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {} |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 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ång | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 823 | void Subtract(const RtpPacketCounter& other) { |
kwiberg | b890c95c | 2016-11-29 13:30:40 | [diff] [blame] | 824 | RTC_DCHECK_GE(header_bytes, other.header_bytes); |
Erik Språng | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 825 | header_bytes -= other.header_bytes; |
kwiberg | b890c95c | 2016-11-29 13:30:40 | [diff] [blame] | 826 | RTC_DCHECK_GE(payload_bytes, other.payload_bytes); |
Erik Språng | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 827 | payload_bytes -= other.payload_bytes; |
kwiberg | b890c95c | 2016-11-29 13:30:40 | [diff] [blame] | 828 | RTC_DCHECK_GE(padding_bytes, other.padding_bytes); |
Erik Språng | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 829 | padding_bytes -= other.padding_bytes; |
kwiberg | b890c95c | 2016-11-29 13:30:40 | [diff] [blame] | 830 | RTC_DCHECK_GE(packets, other.packets); |
Erik Språng | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 831 | packets -= other.packets; |
| 832 | } |
| 833 | |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 834 | 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. |
| 853 | struct StreamDataCounters { |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 | [diff] [blame] | 854 | StreamDataCounters(); |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 855 | |
| 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 && |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 861 | (other.first_packet_time_ms < first_packet_time_ms || |
| 862 | first_packet_time_ms == -1)) { |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 863 | // Use oldest time. |
| 864 | first_packet_time_ms = other.first_packet_time_ms; |
| 865 | } |
| 866 | } |
| 867 | |
Erik Språng | 22c2b48 | 2016-03-01 08:40:42 | [diff] [blame] | 868 | 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.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 880 | 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 | |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 892 | int64_t first_packet_time_ms; // Time when first packet is sent/received. |
| 893 | RtpPacketCounter transmitted; // Number of transmitted packets/bytes. |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 894 | RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes. |
solenberg | 634b86e | 2016-09-01 14:54:53 | [diff] [blame] | 895 | RtpPacketCounter fec; // Number of redundancy packets/bytes. |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 | [diff] [blame] | 896 | }; |
| 897 | |
| 898 | // Callback, called whenever byte/packet counts have been updated. |
| 899 | class StreamDataCountersCallback { |
| 900 | public: |
| 901 | virtual ~StreamDataCountersCallback() {} |
| 902 | |
| 903 | virtual void DataCountersUpdated(const StreamDataCounters& counters, |
| 904 | uint32_t ssrc) = 0; |
| 905 | }; |
pbos | da903ea | 2015-10-02 09:36:56 | [diff] [blame] | 906 | |
| 907 | // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size |
| 908 | // RTCP mode is described by RFC 5506. |
| 909 | enum class RtcpMode { kOff, kCompound, kReducedSize }; |
| 910 | |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 911 | enum NetworkState { |
| 912 | kNetworkUp, |
| 913 | kNetworkDown, |
| 914 | }; |
| 915 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 916 | } // namespace webrtc |
andrew@webrtc.org | eda189b | 2013-09-09 17:50:10 | [diff] [blame] | 917 | |
| 918 | #endif // WEBRTC_COMMON_TYPES_H_ |