1 /*
2  *  Copyright 2019 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 #ifndef RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_LOG_SIMULATION_H_
11 #define RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_LOG_SIMULATION_H_
12 
13 #include <deque>
14 #include <functional>
15 #include <map>
16 #include <memory>
17 #include <vector>
18 
19 #include "api/transport/network_control.h"
20 #include "logging/rtc_event_log/rtc_event_log_parser.h"
21 #include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
22 
23 namespace webrtc {
24 
25 class LogBasedNetworkControllerSimulation {
26  public:
27   explicit LogBasedNetworkControllerSimulation(
28       std::unique_ptr<NetworkControllerFactoryInterface> factory,
29       std::function<void(const NetworkControlUpdate&, Timestamp)>
30           update_handler);
31   ~LogBasedNetworkControllerSimulation();
32   void ProcessEventsInLog(const ParsedRtcEventLog& parsed_log_);
33 
34  private:
35   struct ProbingStatus {
36     const LoggedBweProbeClusterCreatedEvent event;
37     size_t bytes_sent;
38     size_t packets_sent;
39   };
40   void HandleStateUpdate(const NetworkControlUpdate& update);
41   void ProcessUntil(Timestamp to_time);
42 
43   void OnProbeCreated(const LoggedBweProbeClusterCreatedEvent& probe_cluster);
44   void OnPacketSent(const LoggedPacketInfo& packet);
45   void OnFeedback(const LoggedRtcpPacketTransportFeedback& feedback);
46   void OnReceiverReport(const LoggedRtcpPacketReceiverReport& report);
47   void OnIceConfig(const LoggedIceCandidatePairConfig& candidate);
48   RtcEventLogNull null_event_log_;
49 
50   const std::function<void(const NetworkControlUpdate&, Timestamp)>
51       update_handler_;
52   std::unique_ptr<NetworkControllerFactoryInterface> factory_;
53   std::unique_ptr<NetworkControllerInterface> controller_;
54 
55   Timestamp current_time_ = Timestamp::MinusInfinity();
56   Timestamp last_process_ = Timestamp::MinusInfinity();
57   TransportFeedbackAdapter transport_feedback_;
58   std::deque<ProbingStatus> pending_probes_;
59   std::map<uint32_t, rtcp::ReportBlock> last_report_blocks_;
60   Timestamp last_report_block_time_ = Timestamp::MinusInfinity();
61 };
62 }  // namespace webrtc
63 
64 #endif  // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_LOG_SIMULATION_H_
65