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