1 /* 2 * Copyright (c) 2016 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_RTC_EVENT_LOG_UNITTEST_HELPER_H_ 12 #define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_UNITTEST_HELPER_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <memory> 18 19 #include "logging/rtc_event_log/events/rtc_event_alr_state.h" 20 #include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h" 21 #include "logging/rtc_event_log/events/rtc_event_audio_playout.h" 22 #include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h" 23 #include "logging/rtc_event_log/events/rtc_event_audio_send_stream_config.h" 24 #include "logging/rtc_event_log/events/rtc_event_bwe_update_delay_based.h" 25 #include "logging/rtc_event_log/events/rtc_event_bwe_update_loss_based.h" 26 #include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h" 27 #include "logging/rtc_event_log/events/rtc_event_dtls_writable_state.h" 28 #include "logging/rtc_event_log/events/rtc_event_generic_ack_received.h" 29 #include "logging/rtc_event_log/events/rtc_event_generic_packet_received.h" 30 #include "logging/rtc_event_log/events/rtc_event_generic_packet_sent.h" 31 #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h" 32 #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h" 33 #include "logging/rtc_event_log/events/rtc_event_probe_cluster_created.h" 34 #include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h" 35 #include "logging/rtc_event_log/events/rtc_event_probe_result_success.h" 36 #include "logging/rtc_event_log/events/rtc_event_remote_estimate.h" 37 #include "logging/rtc_event_log/events/rtc_event_route_change.h" 38 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h" 39 #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h" 40 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h" 41 #include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h" 42 #include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h" 43 #include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h" 44 #include "logging/rtc_event_log/rtc_event_log_parser.h" 45 #include "logging/rtc_event_log/rtc_stream_config.h" 46 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" 47 #include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" 48 #include "modules/rtp_rtcp/source/rtcp_packet/fir.h" 49 #include "modules/rtp_rtcp/source/rtcp_packet/loss_notification.h" 50 #include "modules/rtp_rtcp/source/rtcp_packet/nack.h" 51 #include "modules/rtp_rtcp/source/rtcp_packet/pli.h" 52 #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" 53 #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" 54 #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h" 55 #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 56 #include "modules/rtp_rtcp/source/rtp_packet.h" 57 #include "rtc_base/random.h" 58 59 namespace webrtc { 60 61 namespace test { 62 63 class EventGenerator { 64 public: EventGenerator(uint64_t seed)65 explicit EventGenerator(uint64_t seed) : prng_(seed) {} 66 67 std::unique_ptr<RtcEventAlrState> NewAlrState(); 68 std::unique_ptr<RtcEventAudioNetworkAdaptation> NewAudioNetworkAdaptation(); 69 std::unique_ptr<RtcEventAudioPlayout> NewAudioPlayout(uint32_t ssrc); 70 std::unique_ptr<RtcEventBweUpdateDelayBased> NewBweUpdateDelayBased(); 71 std::unique_ptr<RtcEventBweUpdateLossBased> NewBweUpdateLossBased(); 72 std::unique_ptr<RtcEventDtlsTransportState> NewDtlsTransportState(); 73 std::unique_ptr<RtcEventDtlsWritableState> NewDtlsWritableState(); 74 std::unique_ptr<RtcEventGenericAckReceived> NewGenericAckReceived(); 75 std::unique_ptr<RtcEventGenericPacketReceived> NewGenericPacketReceived(); 76 std::unique_ptr<RtcEventGenericPacketSent> NewGenericPacketSent(); 77 std::unique_ptr<RtcEventIceCandidatePair> NewIceCandidatePair(); 78 std::unique_ptr<RtcEventIceCandidatePairConfig> NewIceCandidatePairConfig(); 79 std::unique_ptr<RtcEventProbeClusterCreated> NewProbeClusterCreated(); 80 std::unique_ptr<RtcEventProbeResultFailure> NewProbeResultFailure(); 81 std::unique_ptr<RtcEventProbeResultSuccess> NewProbeResultSuccess(); 82 std::unique_ptr<RtcEventRouteChange> NewRouteChange(); 83 std::unique_ptr<RtcEventRemoteEstimate> NewRemoteEstimate(); 84 std::unique_ptr<RtcEventRtcpPacketIncoming> NewRtcpPacketIncoming(); 85 std::unique_ptr<RtcEventRtcpPacketOutgoing> NewRtcpPacketOutgoing(); 86 87 rtcp::SenderReport NewSenderReport(); 88 rtcp::ReceiverReport NewReceiverReport(); 89 rtcp::ExtendedReports NewExtendedReports(); 90 rtcp::Nack NewNack(); 91 rtcp::Remb NewRemb(); 92 rtcp::Fir NewFir(); 93 rtcp::Pli NewPli(); 94 rtcp::TransportFeedback NewTransportFeedback(); 95 rtcp::LossNotification NewLossNotification(); 96 97 // |all_configured_exts| determines whether the RTP packet exhibits all 98 // configured extensions, or a random subset thereof. 99 void RandomizeRtpPacket(size_t payload_size, 100 size_t padding_size, 101 uint32_t ssrc, 102 const RtpHeaderExtensionMap& extension_map, 103 RtpPacket* rtp_packet, 104 bool all_configured_exts); 105 106 // |all_configured_exts| determines whether the RTP packet exhibits all 107 // configured extensions, or a random subset thereof. 108 std::unique_ptr<RtcEventRtpPacketIncoming> NewRtpPacketIncoming( 109 uint32_t ssrc, 110 const RtpHeaderExtensionMap& extension_map, 111 bool all_configured_exts = true); 112 113 // |all_configured_exts| determines whether the RTP packet exhibits all 114 // configured extensions, or a random subset thereof. 115 std::unique_ptr<RtcEventRtpPacketOutgoing> NewRtpPacketOutgoing( 116 uint32_t ssrc, 117 const RtpHeaderExtensionMap& extension_map, 118 bool all_configured_exts = true); 119 120 // |configure_all| determines whether all supported extensions are configured, 121 // or a random subset. 122 RtpHeaderExtensionMap NewRtpHeaderExtensionMap(bool configure_all = false); 123 124 std::unique_ptr<RtcEventAudioReceiveStreamConfig> NewAudioReceiveStreamConfig( 125 uint32_t ssrc, 126 const RtpHeaderExtensionMap& extensions); 127 128 std::unique_ptr<RtcEventAudioSendStreamConfig> NewAudioSendStreamConfig( 129 uint32_t ssrc, 130 const RtpHeaderExtensionMap& extensions); 131 132 std::unique_ptr<RtcEventVideoReceiveStreamConfig> NewVideoReceiveStreamConfig( 133 uint32_t ssrc, 134 const RtpHeaderExtensionMap& extensions); 135 136 std::unique_ptr<RtcEventVideoSendStreamConfig> NewVideoSendStreamConfig( 137 uint32_t ssrc, 138 const RtpHeaderExtensionMap& extensions); 139 140 private: 141 rtcp::ReportBlock NewReportBlock(); 142 int sent_packet_number_ = 0; 143 int received_packet_number_ = 0; 144 145 Random prng_; 146 }; 147 148 class EventVerifier { 149 public: EventVerifier(RtcEventLog::EncodingType encoding_type)150 explicit EventVerifier(RtcEventLog::EncodingType encoding_type) 151 : encoding_type_(encoding_type) {} 152 153 void VerifyLoggedAlrStateEvent(const RtcEventAlrState& original_event, 154 const LoggedAlrStateEvent& logged_event) const; 155 156 void VerifyLoggedAudioPlayoutEvent( 157 const RtcEventAudioPlayout& original_event, 158 const LoggedAudioPlayoutEvent& logged_event) const; 159 160 void VerifyLoggedAudioNetworkAdaptationEvent( 161 const RtcEventAudioNetworkAdaptation& original_event, 162 const LoggedAudioNetworkAdaptationEvent& logged_event) const; 163 164 void VerifyLoggedBweDelayBasedUpdate( 165 const RtcEventBweUpdateDelayBased& original_event, 166 const LoggedBweDelayBasedUpdate& logged_event) const; 167 168 void VerifyLoggedBweLossBasedUpdate( 169 const RtcEventBweUpdateLossBased& original_event, 170 const LoggedBweLossBasedUpdate& logged_event) const; 171 172 void VerifyLoggedBweProbeClusterCreatedEvent( 173 const RtcEventProbeClusterCreated& original_event, 174 const LoggedBweProbeClusterCreatedEvent& logged_event) const; 175 176 void VerifyLoggedBweProbeFailureEvent( 177 const RtcEventProbeResultFailure& original_event, 178 const LoggedBweProbeFailureEvent& logged_event) const; 179 180 void VerifyLoggedBweProbeSuccessEvent( 181 const RtcEventProbeResultSuccess& original_event, 182 const LoggedBweProbeSuccessEvent& logged_event) const; 183 184 void VerifyLoggedDtlsTransportState( 185 const RtcEventDtlsTransportState& original_event, 186 const LoggedDtlsTransportState& logged_event) const; 187 188 void VerifyLoggedDtlsWritableState( 189 const RtcEventDtlsWritableState& original_event, 190 const LoggedDtlsWritableState& logged_event) const; 191 192 void VerifyLoggedIceCandidatePairConfig( 193 const RtcEventIceCandidatePairConfig& original_event, 194 const LoggedIceCandidatePairConfig& logged_event) const; 195 196 void VerifyLoggedIceCandidatePairEvent( 197 const RtcEventIceCandidatePair& original_event, 198 const LoggedIceCandidatePairEvent& logged_event) const; 199 200 void VerifyLoggedRouteChangeEvent( 201 const RtcEventRouteChange& original_event, 202 const LoggedRouteChangeEvent& logged_event) const; 203 204 void VerifyLoggedRemoteEstimateEvent( 205 const RtcEventRemoteEstimate& original_event, 206 const LoggedRemoteEstimateEvent& logged_event) const; 207 208 void VerifyLoggedRtpPacketIncoming( 209 const RtcEventRtpPacketIncoming& original_event, 210 const LoggedRtpPacketIncoming& logged_event) const; 211 212 void VerifyLoggedRtpPacketOutgoing( 213 const RtcEventRtpPacketOutgoing& original_event, 214 const LoggedRtpPacketOutgoing& logged_event) const; 215 216 void VerifyLoggedGenericPacketSent( 217 const RtcEventGenericPacketSent& original_event, 218 const LoggedGenericPacketSent& logged_event) const; 219 220 void VerifyLoggedGenericPacketReceived( 221 const RtcEventGenericPacketReceived& original_event, 222 const LoggedGenericPacketReceived& logged_event) const; 223 224 void VerifyLoggedGenericAckReceived( 225 const RtcEventGenericAckReceived& original_event, 226 const LoggedGenericAckReceived& logged_event) const; 227 228 template <typename EventType, typename ParsedType> VerifyLoggedRtpPacket(const EventType & original_event,const ParsedType & logged_event)229 void VerifyLoggedRtpPacket(const EventType& original_event, 230 const ParsedType& logged_event) { 231 static_assert(sizeof(ParsedType) == 0, 232 "You have to use one of the two defined template " 233 "specializations of VerifyLoggedRtpPacket"); 234 } 235 236 template <> VerifyLoggedRtpPacket(const RtcEventRtpPacketIncoming & original_event,const LoggedRtpPacketIncoming & logged_event)237 void VerifyLoggedRtpPacket(const RtcEventRtpPacketIncoming& original_event, 238 const LoggedRtpPacketIncoming& logged_event) { 239 VerifyLoggedRtpPacketIncoming(original_event, logged_event); 240 } 241 242 template <> VerifyLoggedRtpPacket(const RtcEventRtpPacketOutgoing & original_event,const LoggedRtpPacketOutgoing & logged_event)243 void VerifyLoggedRtpPacket(const RtcEventRtpPacketOutgoing& original_event, 244 const LoggedRtpPacketOutgoing& logged_event) { 245 VerifyLoggedRtpPacketOutgoing(original_event, logged_event); 246 } 247 248 void VerifyLoggedRtcpPacketIncoming( 249 const RtcEventRtcpPacketIncoming& original_event, 250 const LoggedRtcpPacketIncoming& logged_event) const; 251 252 void VerifyLoggedRtcpPacketOutgoing( 253 const RtcEventRtcpPacketOutgoing& original_event, 254 const LoggedRtcpPacketOutgoing& logged_event) const; 255 256 void VerifyLoggedSenderReport(int64_t log_time_us, 257 const rtcp::SenderReport& original_sr, 258 const LoggedRtcpPacketSenderReport& logged_sr); 259 void VerifyLoggedReceiverReport( 260 int64_t log_time_us, 261 const rtcp::ReceiverReport& original_rr, 262 const LoggedRtcpPacketReceiverReport& logged_rr); 263 void VerifyLoggedExtendedReports( 264 int64_t log_time_us, 265 const rtcp::ExtendedReports& original_xr, 266 const LoggedRtcpPacketExtendedReports& logged_xr); 267 void VerifyLoggedFir(int64_t log_time_us, 268 const rtcp::Fir& original_fir, 269 const LoggedRtcpPacketFir& logged_fir); 270 void VerifyLoggedPli(int64_t log_time_us, 271 const rtcp::Pli& original_pli, 272 const LoggedRtcpPacketPli& logged_pli); 273 void VerifyLoggedNack(int64_t log_time_us, 274 const rtcp::Nack& original_nack, 275 const LoggedRtcpPacketNack& logged_nack); 276 void VerifyLoggedTransportFeedback( 277 int64_t log_time_us, 278 const rtcp::TransportFeedback& original_transport_feedback, 279 const LoggedRtcpPacketTransportFeedback& logged_transport_feedback); 280 void VerifyLoggedRemb(int64_t log_time_us, 281 const rtcp::Remb& original_remb, 282 const LoggedRtcpPacketRemb& logged_remb); 283 void VerifyLoggedLossNotification( 284 int64_t log_time_us, 285 const rtcp::LossNotification& original_loss_notification, 286 const LoggedRtcpPacketLossNotification& logged_loss_notification); 287 288 void VerifyLoggedStartEvent(int64_t start_time_us, 289 int64_t utc_start_time_us, 290 const LoggedStartEvent& logged_event) const; 291 void VerifyLoggedStopEvent(int64_t stop_time_us, 292 const LoggedStopEvent& logged_event) const; 293 294 void VerifyLoggedAudioRecvConfig( 295 const RtcEventAudioReceiveStreamConfig& original_event, 296 const LoggedAudioRecvConfig& logged_event) const; 297 298 void VerifyLoggedAudioSendConfig( 299 const RtcEventAudioSendStreamConfig& original_event, 300 const LoggedAudioSendConfig& logged_event) const; 301 302 void VerifyLoggedVideoRecvConfig( 303 const RtcEventVideoReceiveStreamConfig& original_event, 304 const LoggedVideoRecvConfig& logged_event) const; 305 306 void VerifyLoggedVideoSendConfig( 307 const RtcEventVideoSendStreamConfig& original_event, 308 const LoggedVideoSendConfig& logged_event) const; 309 310 private: 311 void VerifyReportBlock(const rtcp::ReportBlock& original_report_block, 312 const rtcp::ReportBlock& logged_report_block); 313 314 RtcEventLog::EncodingType encoding_type_; 315 }; 316 317 } // namespace test 318 } // namespace webrtc 319 320 #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_UNITTEST_HELPER_H_ 321