logged_rtp_rtcp.h (9596B)
1 /* 2 * Copyright 2022 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 11 #ifndef LOGGING_RTC_EVENT_LOG_EVENTS_LOGGED_RTP_RTCP_H_ 12 #define LOGGING_RTC_EVENT_LOG_EVENTS_LOGGED_RTP_RTCP_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <cstring> 17 #include <vector> 18 19 #include "absl/strings/string_view.h" 20 #include "api/rtp_headers.h" 21 #include "api/units/timestamp.h" 22 #include "modules/rtp_rtcp/source/rtcp_packet/bye.h" 23 #include "modules/rtp_rtcp/source/rtcp_packet/congestion_control_feedback.h" 24 #include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" 25 #include "modules/rtp_rtcp/source/rtcp_packet/fir.h" 26 #include "modules/rtp_rtcp/source/rtcp_packet/loss_notification.h" 27 #include "modules/rtp_rtcp/source/rtcp_packet/nack.h" 28 #include "modules/rtp_rtcp/source/rtcp_packet/pli.h" 29 #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" 30 #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" 31 #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 32 #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 33 34 namespace webrtc { 35 36 struct LoggedRtpPacket { 37 LoggedRtpPacket(Timestamp timestamp, 38 RTPHeader header, 39 size_t header_length, 40 size_t total_length) 41 : timestamp(timestamp), 42 header(header), 43 header_length(header_length), 44 total_length(total_length) {} 45 46 int64_t log_time_us() const { return timestamp.us(); } 47 int64_t log_time_ms() const { return timestamp.ms(); } 48 Timestamp log_time() const { return timestamp; } 49 50 Timestamp timestamp; 51 // TODO(terelius): This allocates space for 15 CSRCs even if none are used. 52 RTPHeader header; 53 // RTPHeader::extension is a mess, save DD wire format instead. 54 std::vector<uint8_t> dependency_descriptor_wire_format; 55 size_t header_length; 56 size_t total_length; 57 }; 58 59 struct LoggedRtpPacketIncoming { 60 LoggedRtpPacketIncoming(Timestamp timestamp, 61 RTPHeader header, 62 size_t header_length, 63 size_t total_length) 64 : rtp(timestamp, header, header_length, total_length) {} 65 int64_t log_time_us() const { return rtp.timestamp.us(); } 66 int64_t log_time_ms() const { return rtp.timestamp.ms(); } 67 Timestamp log_time() const { return rtp.timestamp; } 68 69 LoggedRtpPacket rtp; 70 }; 71 72 struct LoggedRtpPacketOutgoing { 73 LoggedRtpPacketOutgoing(Timestamp timestamp, 74 RTPHeader header, 75 size_t header_length, 76 size_t total_length) 77 : rtp(timestamp, header, header_length, total_length) {} 78 int64_t log_time_us() const { return rtp.timestamp.us(); } 79 int64_t log_time_ms() const { return rtp.timestamp.ms(); } 80 Timestamp log_time() const { return rtp.timestamp; } 81 82 LoggedRtpPacket rtp; 83 }; 84 85 struct LoggedRtcpPacket { 86 LoggedRtcpPacket(Timestamp timestamp, const std::vector<uint8_t>& packet) 87 : timestamp(timestamp), raw_data(packet) {} 88 LoggedRtcpPacket(Timestamp timestamp, absl::string_view packet) 89 : timestamp(timestamp), raw_data(packet.size()) { 90 memcpy(raw_data.data(), packet.data(), packet.size()); 91 } 92 93 LoggedRtcpPacket(const LoggedRtcpPacket& rhs) = default; 94 95 ~LoggedRtcpPacket() = default; 96 97 int64_t log_time_us() const { return timestamp.us(); } 98 int64_t log_time_ms() const { return timestamp.ms(); } 99 Timestamp log_time() const { return timestamp; } 100 101 Timestamp timestamp; 102 std::vector<uint8_t> raw_data; 103 }; 104 105 struct LoggedRtcpPacketIncoming { 106 LoggedRtcpPacketIncoming(Timestamp timestamp, 107 const std::vector<uint8_t>& packet) 108 : rtcp(timestamp, packet) {} 109 LoggedRtcpPacketIncoming(Timestamp timestamp, absl::string_view packet) 110 : rtcp(timestamp, packet) {} 111 112 int64_t log_time_us() const { return rtcp.timestamp.us(); } 113 int64_t log_time_ms() const { return rtcp.timestamp.ms(); } 114 Timestamp log_time() const { return rtcp.timestamp; } 115 116 LoggedRtcpPacket rtcp; 117 }; 118 119 struct LoggedRtcpPacketOutgoing { 120 LoggedRtcpPacketOutgoing(Timestamp timestamp, 121 const std::vector<uint8_t>& packet) 122 : rtcp(timestamp, packet) {} 123 LoggedRtcpPacketOutgoing(Timestamp timestamp, absl::string_view packet) 124 : rtcp(timestamp, packet) {} 125 126 int64_t log_time_us() const { return rtcp.timestamp.us(); } 127 int64_t log_time_ms() const { return rtcp.timestamp.ms(); } 128 Timestamp log_time() const { return rtcp.timestamp; } 129 130 LoggedRtcpPacket rtcp; 131 }; 132 133 struct LoggedRtcpPacketReceiverReport { 134 LoggedRtcpPacketReceiverReport() = default; 135 LoggedRtcpPacketReceiverReport(Timestamp timestamp, 136 const rtcp::ReceiverReport& rr) 137 : timestamp(timestamp), rr(rr) {} 138 139 int64_t log_time_us() const { return timestamp.us(); } 140 int64_t log_time_ms() const { return timestamp.ms(); } 141 Timestamp log_time() const { return timestamp; } 142 143 Timestamp timestamp = Timestamp::MinusInfinity(); 144 rtcp::ReceiverReport rr; 145 }; 146 147 struct LoggedRtcpPacketSenderReport { 148 LoggedRtcpPacketSenderReport() = default; 149 LoggedRtcpPacketSenderReport(Timestamp timestamp, 150 const rtcp::SenderReport& sr) 151 : timestamp(timestamp), sr(sr) {} 152 153 int64_t log_time_us() const { return timestamp.us(); } 154 int64_t log_time_ms() const { return timestamp.ms(); } 155 Timestamp log_time() const { return timestamp; } 156 157 Timestamp timestamp = Timestamp::MinusInfinity(); 158 rtcp::SenderReport sr; 159 }; 160 161 struct LoggedRtcpPacketExtendedReports { 162 LoggedRtcpPacketExtendedReports() = default; 163 164 int64_t log_time_us() const { return timestamp.us(); } 165 int64_t log_time_ms() const { return timestamp.ms(); } 166 Timestamp log_time() const { return timestamp; } 167 168 Timestamp timestamp = Timestamp::MinusInfinity(); 169 rtcp::ExtendedReports xr; 170 }; 171 172 struct LoggedRtcpPacketRemb { 173 LoggedRtcpPacketRemb() = default; 174 LoggedRtcpPacketRemb(Timestamp timestamp, const rtcp::Remb& remb) 175 : timestamp(timestamp), remb(remb) {} 176 177 int64_t log_time_us() const { return timestamp.us(); } 178 int64_t log_time_ms() const { return timestamp.ms(); } 179 Timestamp log_time() const { return timestamp; } 180 181 Timestamp timestamp = Timestamp::MinusInfinity(); 182 rtcp::Remb remb; 183 }; 184 185 struct LoggedRtcpPacketNack { 186 LoggedRtcpPacketNack() = default; 187 LoggedRtcpPacketNack(Timestamp timestamp, const rtcp::Nack& nack) 188 : timestamp(timestamp), nack(nack) {} 189 190 int64_t log_time_us() const { return timestamp.us(); } 191 int64_t log_time_ms() const { return timestamp.ms(); } 192 Timestamp log_time() const { return timestamp; } 193 194 Timestamp timestamp = Timestamp::MinusInfinity(); 195 rtcp::Nack nack; 196 }; 197 198 struct LoggedRtcpPacketFir { 199 LoggedRtcpPacketFir() = default; 200 201 int64_t log_time_us() const { return timestamp.us(); } 202 int64_t log_time_ms() const { return timestamp.ms(); } 203 Timestamp log_time() const { return timestamp; } 204 205 Timestamp timestamp = Timestamp::MinusInfinity(); 206 rtcp::Fir fir; 207 }; 208 209 struct LoggedRtcpPacketPli { 210 LoggedRtcpPacketPli() = default; 211 212 int64_t log_time_us() const { return timestamp.us(); } 213 int64_t log_time_ms() const { return timestamp.ms(); } 214 Timestamp log_time() const { return timestamp; } 215 216 Timestamp timestamp = Timestamp::MinusInfinity(); 217 rtcp::Pli pli; 218 }; 219 220 struct LoggedRtcpPacketTransportFeedback { 221 LoggedRtcpPacketTransportFeedback() 222 : transport_feedback(/*include_timestamps=*/true) {} 223 LoggedRtcpPacketTransportFeedback( 224 Timestamp timestamp, 225 const rtcp::TransportFeedback& transport_feedback) 226 : timestamp(timestamp), transport_feedback(transport_feedback) {} 227 228 int64_t log_time_us() const { return timestamp.us(); } 229 int64_t log_time_ms() const { return timestamp.ms(); } 230 Timestamp log_time() const { return timestamp; } 231 232 Timestamp timestamp = Timestamp::MinusInfinity(); 233 rtcp::TransportFeedback transport_feedback; 234 }; 235 236 struct LoggedRtcpCongestionControlFeedback { 237 LoggedRtcpCongestionControlFeedback( 238 Timestamp timestamp, 239 const rtcp::CongestionControlFeedback& congestion_feedback) 240 : timestamp(timestamp), congestion_feedback(congestion_feedback) {} 241 242 int64_t log_time_us() const { return timestamp.us(); } 243 int64_t log_time_ms() const { return timestamp.ms(); } 244 Timestamp log_time() const { return timestamp; } 245 246 Timestamp timestamp; 247 rtcp::CongestionControlFeedback congestion_feedback; 248 }; 249 250 struct LoggedRtcpPacketLossNotification { 251 LoggedRtcpPacketLossNotification() = default; 252 LoggedRtcpPacketLossNotification( 253 Timestamp timestamp, 254 const rtcp::LossNotification& loss_notification) 255 : timestamp(timestamp), loss_notification(loss_notification) {} 256 257 int64_t log_time_us() const { return timestamp.us(); } 258 int64_t log_time_ms() const { return timestamp.ms(); } 259 Timestamp log_time() const { return timestamp; } 260 261 Timestamp timestamp = Timestamp::MinusInfinity(); 262 rtcp::LossNotification loss_notification; 263 }; 264 265 struct LoggedRtcpPacketBye { 266 LoggedRtcpPacketBye() = default; 267 268 int64_t log_time_us() const { return timestamp.us(); } 269 int64_t log_time_ms() const { return timestamp.ms(); } 270 Timestamp log_time() const { return timestamp; } 271 272 Timestamp timestamp = Timestamp::MinusInfinity(); 273 rtcp::Bye bye; 274 }; 275 276 } // namespace webrtc 277 278 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_LOGGED_RTP_RTCP_H_