packet_sender.h 2.1 KB

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