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 <string> 15 #include <vector> 16 17 #include "absl/strings/string_view.h" 18 #include "api/rtp_headers.h" 19 #include "api/units/timestamp.h" 20 #include "modules/rtp_rtcp/source/rtcp_packet/bye.h" 21 #include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" 22 #include "modules/rtp_rtcp/source/rtcp_packet/fir.h" 23 #include "modules/rtp_rtcp/source/rtcp_packet/loss_notification.h" 24 #include "modules/rtp_rtcp/source/rtcp_packet/nack.h" 25 #include "modules/rtp_rtcp/source/rtcp_packet/pli.h" 26 #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" 27 #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" 28 #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 29 #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 30 31 namespace webrtc { 32 33 struct LoggedRtpPacket { LoggedRtpPacketLoggedRtpPacket34 LoggedRtpPacket(Timestamp timestamp, 35 RTPHeader header, 36 size_t header_length, 37 size_t total_length) 38 : timestamp(timestamp), 39 header(header), 40 header_length(header_length), 41 total_length(total_length) {} 42 log_time_usLoggedRtpPacket43 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtpPacket44 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtpPacket45 Timestamp log_time() const { return timestamp; } 46 47 Timestamp timestamp; 48 // TODO(terelius): This allocates space for 15 CSRCs even if none are used. 49 RTPHeader header; 50 size_t header_length; 51 size_t total_length; 52 }; 53 54 struct LoggedRtpPacketIncoming { LoggedRtpPacketIncomingLoggedRtpPacketIncoming55 LoggedRtpPacketIncoming(Timestamp timestamp, 56 RTPHeader header, 57 size_t header_length, 58 size_t total_length) 59 : rtp(timestamp, header, header_length, total_length) {} log_time_usLoggedRtpPacketIncoming60 int64_t log_time_us() const { return rtp.timestamp.us(); } log_time_msLoggedRtpPacketIncoming61 int64_t log_time_ms() const { return rtp.timestamp.ms(); } log_timeLoggedRtpPacketIncoming62 Timestamp log_time() const { return rtp.timestamp; } 63 64 LoggedRtpPacket rtp; 65 }; 66 67 struct LoggedRtpPacketOutgoing { LoggedRtpPacketOutgoingLoggedRtpPacketOutgoing68 LoggedRtpPacketOutgoing(Timestamp timestamp, 69 RTPHeader header, 70 size_t header_length, 71 size_t total_length) 72 : rtp(timestamp, header, header_length, total_length) {} log_time_usLoggedRtpPacketOutgoing73 int64_t log_time_us() const { return rtp.timestamp.us(); } log_time_msLoggedRtpPacketOutgoing74 int64_t log_time_ms() const { return rtp.timestamp.ms(); } log_timeLoggedRtpPacketOutgoing75 Timestamp log_time() const { return rtp.timestamp; } 76 77 LoggedRtpPacket rtp; 78 }; 79 80 struct LoggedRtcpPacket { LoggedRtcpPacketLoggedRtcpPacket81 LoggedRtcpPacket(Timestamp timestamp, const std::vector<uint8_t>& packet) 82 : timestamp(timestamp), raw_data(packet) {} LoggedRtcpPacketLoggedRtcpPacket83 LoggedRtcpPacket(Timestamp timestamp, absl::string_view packet) 84 : timestamp(timestamp), raw_data(packet.size()) { 85 memcpy(raw_data.data(), packet.data(), packet.size()); 86 } 87 88 LoggedRtcpPacket(const LoggedRtcpPacket& rhs) = default; 89 90 ~LoggedRtcpPacket() = default; 91 log_time_usLoggedRtcpPacket92 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacket93 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacket94 Timestamp log_time() const { return timestamp; } 95 96 Timestamp timestamp; 97 std::vector<uint8_t> raw_data; 98 }; 99 100 struct LoggedRtcpPacketIncoming { LoggedRtcpPacketIncomingLoggedRtcpPacketIncoming101 LoggedRtcpPacketIncoming(Timestamp timestamp, 102 const std::vector<uint8_t>& packet) 103 : rtcp(timestamp, packet) {} LoggedRtcpPacketIncomingLoggedRtcpPacketIncoming104 LoggedRtcpPacketIncoming(Timestamp timestamp, absl::string_view packet) 105 : rtcp(timestamp, packet) {} 106 log_time_usLoggedRtcpPacketIncoming107 int64_t log_time_us() const { return rtcp.timestamp.us(); } log_time_msLoggedRtcpPacketIncoming108 int64_t log_time_ms() const { return rtcp.timestamp.ms(); } log_timeLoggedRtcpPacketIncoming109 Timestamp log_time() const { return rtcp.timestamp; } 110 111 LoggedRtcpPacket rtcp; 112 }; 113 114 struct LoggedRtcpPacketOutgoing { LoggedRtcpPacketOutgoingLoggedRtcpPacketOutgoing115 LoggedRtcpPacketOutgoing(Timestamp timestamp, 116 const std::vector<uint8_t>& packet) 117 : rtcp(timestamp, packet) {} LoggedRtcpPacketOutgoingLoggedRtcpPacketOutgoing118 LoggedRtcpPacketOutgoing(Timestamp timestamp, absl::string_view packet) 119 : rtcp(timestamp, packet) {} 120 log_time_usLoggedRtcpPacketOutgoing121 int64_t log_time_us() const { return rtcp.timestamp.us(); } log_time_msLoggedRtcpPacketOutgoing122 int64_t log_time_ms() const { return rtcp.timestamp.ms(); } log_timeLoggedRtcpPacketOutgoing123 Timestamp log_time() const { return rtcp.timestamp; } 124 125 LoggedRtcpPacket rtcp; 126 }; 127 128 struct LoggedRtcpPacketReceiverReport { 129 LoggedRtcpPacketReceiverReport() = default; LoggedRtcpPacketReceiverReportLoggedRtcpPacketReceiverReport130 LoggedRtcpPacketReceiverReport(Timestamp timestamp, 131 const rtcp::ReceiverReport& rr) 132 : timestamp(timestamp), rr(rr) {} 133 log_time_usLoggedRtcpPacketReceiverReport134 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketReceiverReport135 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketReceiverReport136 Timestamp log_time() const { return timestamp; } 137 138 Timestamp timestamp = Timestamp::MinusInfinity(); 139 rtcp::ReceiverReport rr; 140 }; 141 142 struct LoggedRtcpPacketSenderReport { 143 LoggedRtcpPacketSenderReport() = default; LoggedRtcpPacketSenderReportLoggedRtcpPacketSenderReport144 LoggedRtcpPacketSenderReport(Timestamp timestamp, 145 const rtcp::SenderReport& sr) 146 : timestamp(timestamp), sr(sr) {} 147 log_time_usLoggedRtcpPacketSenderReport148 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketSenderReport149 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketSenderReport150 Timestamp log_time() const { return timestamp; } 151 152 Timestamp timestamp = Timestamp::MinusInfinity(); 153 rtcp::SenderReport sr; 154 }; 155 156 struct LoggedRtcpPacketExtendedReports { 157 LoggedRtcpPacketExtendedReports() = default; 158 log_time_usLoggedRtcpPacketExtendedReports159 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketExtendedReports160 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketExtendedReports161 Timestamp log_time() const { return timestamp; } 162 163 Timestamp timestamp = Timestamp::MinusInfinity(); 164 rtcp::ExtendedReports xr; 165 }; 166 167 struct LoggedRtcpPacketRemb { 168 LoggedRtcpPacketRemb() = default; LoggedRtcpPacketRembLoggedRtcpPacketRemb169 LoggedRtcpPacketRemb(Timestamp timestamp, const rtcp::Remb& remb) 170 : timestamp(timestamp), remb(remb) {} 171 log_time_usLoggedRtcpPacketRemb172 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketRemb173 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketRemb174 Timestamp log_time() const { return timestamp; } 175 176 Timestamp timestamp = Timestamp::MinusInfinity(); 177 rtcp::Remb remb; 178 }; 179 180 struct LoggedRtcpPacketNack { 181 LoggedRtcpPacketNack() = default; LoggedRtcpPacketNackLoggedRtcpPacketNack182 LoggedRtcpPacketNack(Timestamp timestamp, const rtcp::Nack& nack) 183 : timestamp(timestamp), nack(nack) {} 184 log_time_usLoggedRtcpPacketNack185 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketNack186 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketNack187 Timestamp log_time() const { return timestamp; } 188 189 Timestamp timestamp = Timestamp::MinusInfinity(); 190 rtcp::Nack nack; 191 }; 192 193 struct LoggedRtcpPacketFir { 194 LoggedRtcpPacketFir() = default; 195 log_time_usLoggedRtcpPacketFir196 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketFir197 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketFir198 Timestamp log_time() const { return timestamp; } 199 200 Timestamp timestamp = Timestamp::MinusInfinity(); 201 rtcp::Fir fir; 202 }; 203 204 struct LoggedRtcpPacketPli { 205 LoggedRtcpPacketPli() = default; 206 log_time_usLoggedRtcpPacketPli207 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketPli208 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketPli209 Timestamp log_time() const { return timestamp; } 210 211 Timestamp timestamp = Timestamp::MinusInfinity(); 212 rtcp::Pli pli; 213 }; 214 215 struct LoggedRtcpPacketTransportFeedback { LoggedRtcpPacketTransportFeedbackLoggedRtcpPacketTransportFeedback216 LoggedRtcpPacketTransportFeedback() 217 : transport_feedback(/*include_timestamps=*/true, /*include_lost*/ true) { 218 } LoggedRtcpPacketTransportFeedbackLoggedRtcpPacketTransportFeedback219 LoggedRtcpPacketTransportFeedback( 220 Timestamp timestamp, 221 const rtcp::TransportFeedback& transport_feedback) 222 : timestamp(timestamp), transport_feedback(transport_feedback) {} 223 log_time_usLoggedRtcpPacketTransportFeedback224 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketTransportFeedback225 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketTransportFeedback226 Timestamp log_time() const { return timestamp; } 227 228 Timestamp timestamp = Timestamp::MinusInfinity(); 229 rtcp::TransportFeedback transport_feedback; 230 }; 231 232 struct LoggedRtcpPacketLossNotification { 233 LoggedRtcpPacketLossNotification() = default; LoggedRtcpPacketLossNotificationLoggedRtcpPacketLossNotification234 LoggedRtcpPacketLossNotification( 235 Timestamp timestamp, 236 const rtcp::LossNotification& loss_notification) 237 : timestamp(timestamp), loss_notification(loss_notification) {} 238 log_time_usLoggedRtcpPacketLossNotification239 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketLossNotification240 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketLossNotification241 Timestamp log_time() const { return timestamp; } 242 243 Timestamp timestamp = Timestamp::MinusInfinity(); 244 rtcp::LossNotification loss_notification; 245 }; 246 247 struct LoggedRtcpPacketBye { 248 LoggedRtcpPacketBye() = default; 249 log_time_usLoggedRtcpPacketBye250 int64_t log_time_us() const { return timestamp.us(); } log_time_msLoggedRtcpPacketBye251 int64_t log_time_ms() const { return timestamp.ms(); } log_timeLoggedRtcpPacketBye252 Timestamp log_time() const { return timestamp; } 253 254 Timestamp timestamp = Timestamp::MinusInfinity(); 255 rtcp::Bye bye; 256 }; 257 258 } // namespace webrtc 259 260 #endif // LOGGING_RTC_EVENT_LOG_EVENTS_LOGGED_RTP_RTCP_H_ 261