control_handler.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2018 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 MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_
  11. #define MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_
  12. #include <stdint.h>
  13. #include "absl/types/optional.h"
  14. #include "api/transport/network_types.h"
  15. #include "api/units/data_size.h"
  16. #include "api/units/time_delta.h"
  17. #include "modules/pacing/paced_sender.h"
  18. #include "rtc_base/constructor_magic.h"
  19. #include "rtc_base/synchronization/sequence_checker.h"
  20. #include "rtc_base/system/no_unique_address.h"
  21. namespace webrtc {
  22. // This is used to observe the network controller state and route calls to
  23. // the proper handler. It also keeps cached values for safe asynchronous use.
  24. // This makes sure that things running on the worker queue can't access state
  25. // in RtpTransportControllerSend, which would risk causing data race on
  26. // destruction unless members are properly ordered.
  27. class CongestionControlHandler {
  28. public:
  29. CongestionControlHandler();
  30. ~CongestionControlHandler();
  31. void SetTargetRate(TargetTransferRate new_target_rate);
  32. void SetNetworkAvailability(bool network_available);
  33. void SetPacerQueue(TimeDelta expected_queue_time);
  34. absl::optional<TargetTransferRate> GetUpdate();
  35. private:
  36. absl::optional<TargetTransferRate> last_incoming_;
  37. absl::optional<TargetTransferRate> last_reported_;
  38. bool network_available_ = true;
  39. bool encoder_paused_in_last_report_ = false;
  40. const bool disable_pacer_emergency_stop_;
  41. int64_t pacer_expected_queue_ms_ = 0;
  42. RTC_NO_UNIQUE_ADDRESS SequenceChecker sequenced_checker_;
  43. RTC_DISALLOW_COPY_AND_ASSIGN(CongestionControlHandler);
  44. };
  45. } // namespace webrtc
  46. #endif // MODULES_CONGESTION_CONTROLLER_RTP_CONTROL_HANDLER_H_