1 /*
2  *  Copyright 2017 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 RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_
12 #define RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "api/task_queue/task_queue_factory.h"
18 #include "rtc_base/constructor_magic.h"
19 #include "rtc_base/ignore_wundef.h"
20 #include "rtc_base/synchronization/sequence_checker.h"
21 #include "rtc_base/task_queue.h"
22 
23 #ifdef WEBRTC_NETWORK_TESTER_PROTO
24 RTC_PUSH_IGNORING_WUNDEF()
25 #include "rtc_tools/network_tester/network_tester_packet.pb.h"
26 RTC_POP_IGNORING_WUNDEF()
27 using webrtc::network_tester::packet::NetworkTesterPacket;
28 #else
29 class NetworkTesterPacket;
30 #endif  // WEBRTC_NETWORK_TESTER_PROTO
31 
32 namespace webrtc {
33 
34 class TestController;
35 
36 class PacketSender {
37  public:
38   PacketSender(TestController* test_controller,
39                const std::string& config_file_path);
40   ~PacketSender();
41 
42   void StartSending();
43   void StopSending();
44   bool IsSending() const;
45 
46   void SendPacket();
47 
48   int64_t GetSendIntervalMs() const;
49   void UpdateTestSetting(size_t packet_size, int64_t send_interval_ms);
50 
51  private:
52   SequenceChecker worker_queue_checker_;
53   size_t packet_size_ RTC_GUARDED_BY(worker_queue_checker_);
54   int64_t send_interval_ms_ RTC_GUARDED_BY(worker_queue_checker_);
55   int64_t sequence_number_ RTC_GUARDED_BY(worker_queue_checker_);
56   bool sending_ RTC_GUARDED_BY(worker_queue_checker_);
57   const std::string config_file_path_;
58   TestController* const test_controller_;
59   std::unique_ptr<TaskQueueFactory> task_queue_factory_;
60   rtc::TaskQueue worker_queue_;
61 
62   RTC_DISALLOW_COPY_AND_ASSIGN(PacketSender);
63 };
64 
65 }  // namespace webrtc
66 
67 #endif  // RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_
68