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