You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2016 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_VIDEO_CODING_NACK_MODULE_H_
  11. #define MODULES_VIDEO_CODING_NACK_MODULE_H_
  12. #include <stdint.h>
  13. #include <map>
  14. #include <set>
  15. #include <vector>
  16. #include "modules/include/module.h"
  17. #include "modules/include/module_common_types.h"
  18. #include "modules/video_coding/histogram.h"
  19. #include "rtc_base/critical_section.h"
  20. #include "rtc_base/numerics/sequence_number_util.h"
  21. #include "rtc_base/thread_annotations.h"
  22. #include "system_wrappers/include/clock.h"
  23. namespace webrtc {
  24. class NackModule : public Module {
  25. public:
  26. NackModule(Clock* clock,
  27. NackSender* nack_sender,
  28. KeyFrameRequestSender* keyframe_request_sender);
  29. int OnReceivedPacket(uint16_t seq_num, bool is_keyframe);
  30. int OnReceivedPacket(uint16_t seq_num, bool is_keyframe, bool is_recovered);
  31. void ClearUpTo(uint16_t seq_num);
  32. void UpdateRtt(int64_t rtt_ms);
  33. void Clear();
  34. // Module implementation
  35. int64_t TimeUntilNextProcess() override;
  36. void Process() override;
  37. private:
  38. // Which fields to consider when deciding which packet to nack in
  39. // GetNackBatch.
  40. enum NackFilterOptions { kSeqNumOnly, kTimeOnly, kSeqNumAndTime };
  41. // This class holds the sequence number of the packet that is in the nack list
  42. // as well as the meta data about when it should be nacked and how many times
  43. // we have tried to nack this packet.
  44. struct NackInfo {
  45. NackInfo();
  46. NackInfo(uint16_t seq_num,
  47. uint16_t send_at_seq_num,
  48. int64_t created_at_time);
  49. uint16_t seq_num;
  50. uint16_t send_at_seq_num;
  51. int64_t created_at_time;
  52. int64_t sent_at_time;
  53. int retries;
  54. };
  55. void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end)
  56. RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  57. // Removes packets from the nack list until the next keyframe. Returns true
  58. // if packets were removed.
  59. bool RemovePacketsUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  60. std::vector<uint16_t> GetNackBatch(NackFilterOptions options)
  61. RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  62. // Update the reordering distribution.
  63. void UpdateReorderingStatistics(uint16_t seq_num)
  64. RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  65. // Returns how many packets we have to wait in order to receive the packet
  66. // with probability |probabilty| or higher.
  67. int WaitNumberOfPackets(float probability) const
  68. RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  69. rtc::CriticalSection crit_;
  70. Clock* const clock_;
  71. NackSender* const nack_sender_;
  72. KeyFrameRequestSender* const keyframe_request_sender_;
  73. // TODO(philipel): Some of the variables below are consistently used on a
  74. // known thread (e.g. see |initialized_|). Those probably do not need
  75. // synchronized access.
  76. std::map<uint16_t, NackInfo, DescendingSeqNumComp<uint16_t>> nack_list_
  77. RTC_GUARDED_BY(crit_);
  78. std::set<uint16_t, DescendingSeqNumComp<uint16_t>> keyframe_list_
  79. RTC_GUARDED_BY(crit_);
  80. std::set<uint16_t, DescendingSeqNumComp<uint16_t>> recovered_list_
  81. RTC_GUARDED_BY(crit_);
  82. video_coding::Histogram reordering_histogram_ RTC_GUARDED_BY(crit_);
  83. bool initialized_ RTC_GUARDED_BY(crit_);
  84. int64_t rtt_ms_ RTC_GUARDED_BY(crit_);
  85. uint16_t newest_seq_num_ RTC_GUARDED_BY(crit_);
  86. // Only touched on the process thread.
  87. int64_t next_process_time_ms_;
  88. // Adds a delay before send nack on packet received.
  89. const int64_t send_nack_delay_ms_;
  90. };
  91. } // namespace webrtc
  92. #endif // MODULES_VIDEO_CODING_NACK_MODULE_H_