minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_ |
| 12 | #define RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_ |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 17 | #include "api/sequence_checker.h" |
Danil Chapovalov | 3993b18 | 2019-03-27 18:42:15 | [diff] [blame] | 18 | #include "api/task_queue/task_queue_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "rtc_base/constructor_magic.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "rtc_base/ignore_wundef.h" |
Mirko Bonadei | 20e4c80 | 2020-11-23 10:07:42 | [diff] [blame] | 21 | #include "rtc_base/system/no_unique_address.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "rtc_base/task_queue.h" |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 23 | |
| 24 | #ifdef WEBRTC_NETWORK_TESTER_PROTO |
| 25 | RTC_PUSH_IGNORING_WUNDEF() |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 26 | #include "rtc_tools/network_tester/network_tester_packet.pb.h" |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 27 | RTC_POP_IGNORING_WUNDEF() |
| 28 | using webrtc::network_tester::packet::NetworkTesterPacket; |
| 29 | #else |
| 30 | class NetworkTesterPacket; |
| 31 | #endif // WEBRTC_NETWORK_TESTER_PROTO |
| 32 | |
| 33 | namespace webrtc { |
| 34 | |
| 35 | class TestController; |
| 36 | |
| 37 | class PacketSender { |
| 38 | public: |
| 39 | PacketSender(TestController* test_controller, |
| 40 | const std::string& config_file_path); |
| 41 | ~PacketSender(); |
| 42 | |
| 43 | void StartSending(); |
| 44 | void StopSending(); |
| 45 | bool IsSending() const; |
| 46 | |
| 47 | void SendPacket(); |
| 48 | |
| 49 | int64_t GetSendIntervalMs() const; |
| 50 | void UpdateTestSetting(size_t packet_size, int64_t send_interval_ms); |
| 51 | |
| 52 | private: |
Mirko Bonadei | 20e4c80 | 2020-11-23 10:07:42 | [diff] [blame] | 53 | RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_queue_checker_; |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 54 | size_t packet_size_ RTC_GUARDED_BY(worker_queue_checker_); |
| 55 | int64_t send_interval_ms_ RTC_GUARDED_BY(worker_queue_checker_); |
| 56 | int64_t sequence_number_ RTC_GUARDED_BY(worker_queue_checker_); |
| 57 | bool sending_ RTC_GUARDED_BY(worker_queue_checker_); |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 58 | const std::string config_file_path_; |
| 59 | TestController* const test_controller_; |
Danil Chapovalov | 3993b18 | 2019-03-27 18:42:15 | [diff] [blame] | 60 | std::unique_ptr<TaskQueueFactory> task_queue_factory_; |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 61 | rtc::TaskQueue worker_queue_; |
| 62 | |
| 63 | RTC_DISALLOW_COPY_AND_ASSIGN(PacketSender); |
| 64 | }; |
| 65 | |
| 66 | } // namespace webrtc |
| 67 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 68 | #endif // RTC_TOOLS_NETWORK_TESTER_PACKET_SENDER_H_ |