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