OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "webrtc/system_wrappers/include/clock.h" | 25 #include "webrtc/system_wrappers/include/clock.h" |
26 | 26 |
27 namespace webrtc { | 27 namespace webrtc { |
28 | 28 |
29 class NackModule : public Module { | 29 class NackModule : public Module { |
30 public: | 30 public: |
31 NackModule(Clock* clock, | 31 NackModule(Clock* clock, |
32 NackSender* nack_sender, | 32 NackSender* nack_sender, |
33 KeyFrameRequestSender* keyframe_request_sender); | 33 KeyFrameRequestSender* keyframe_request_sender); |
34 | 34 |
35 void OnReceivedPacket(const VCMPacket& packet); | 35 int OnReceivedPacket(const VCMPacket& packet); |
36 void ClearUpTo(uint16_t seq_num); | 36 void ClearUpTo(uint16_t seq_num); |
37 void UpdateRtt(int64_t rtt_ms); | 37 void UpdateRtt(int64_t rtt_ms); |
38 void Clear(); | 38 void Clear(); |
39 void Stop(); | 39 void Stop(); |
40 | 40 |
41 // Module implementation | 41 // Module implementation |
42 int64_t TimeUntilNextProcess() override; | 42 int64_t TimeUntilNextProcess() override; |
43 void Process() override; | 43 void Process() override; |
44 | 44 |
45 private: | 45 private: |
46 // Which fields to consider when deciding which packet to nack in | 46 // Which fields to consider when deciding which packet to nack in |
47 // GetNackBatch. | 47 // GetNackBatch. |
48 enum NackFilterOptions { kSeqNumOnly, kTimeOnly, kSeqNumAndTime }; | 48 enum NackFilterOptions { kSeqNumOnly, kTimeOnly, kSeqNumAndTime }; |
49 | 49 |
50 // This class holds the sequence number of the packet that is in the nack list | 50 // This class holds the sequence number of the packet that is in the nack list |
51 // as well as the meta data about when it should be nacked and how many times | 51 // as well as the meta data about when it should be nacked and how many times |
52 // we have tried to nack this packet. | 52 // we have tried to nack this packet. |
53 struct NackInfo { | 53 struct NackInfo { |
54 NackInfo(); | 54 NackInfo(); |
55 NackInfo(uint16_t seq_num, uint16_t send_at_seq_num); | 55 NackInfo(uint16_t seq_num, uint16_t send_at_seq_num); |
56 | 56 |
57 uint16_t seq_num; | 57 uint16_t seq_num; |
58 uint16_t send_at_seq_num; | 58 uint16_t send_at_seq_num; |
59 int64_t sent_at_time; | 59 int64_t sent_at_time; |
60 int retries; | 60 int retries; |
61 }; | 61 }; |
62 | |
63 struct SeqNumComparator { | |
64 bool operator()(uint16_t s1, uint16_t s2) const { return AheadOf(s2, s1); } | |
65 }; | |
66 | |
67 void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end) | 62 void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end) |
68 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 63 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
69 | 64 |
70 // Removes packets from the nack list until the next keyframe. Returns true | 65 // Removes packets from the nack list until the next keyframe. Returns true |
71 // if packets were removed. | 66 // if packets were removed. |
72 bool RemovePacketsUntilKeyFrame() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 67 bool RemovePacketsUntilKeyFrame() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
73 std::vector<uint16_t> GetNackBatch(NackFilterOptions options) | 68 std::vector<uint16_t> GetNackBatch(NackFilterOptions options) |
74 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 69 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
75 | 70 |
76 // Update the reordering distribution. | 71 // Update the reordering distribution. |
77 void UpdateReorderingStatistics(uint16_t seq_num) | 72 void UpdateReorderingStatistics(uint16_t seq_num) |
78 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 73 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
79 | 74 |
80 // Returns how many packets we have to wait in order to receive the packet | 75 // Returns how many packets we have to wait in order to receive the packet |
81 // with probability |probabilty| or higher. | 76 // with probability |probabilty| or higher. |
82 int WaitNumberOfPackets(float probability) const | 77 int WaitNumberOfPackets(float probability) const |
83 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 78 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
84 | 79 |
85 rtc::CriticalSection crit_; | 80 rtc::CriticalSection crit_; |
86 Clock* const clock_; | 81 Clock* const clock_; |
87 NackSender* const nack_sender_; | 82 NackSender* const nack_sender_; |
88 KeyFrameRequestSender* const keyframe_request_sender_; | 83 KeyFrameRequestSender* const keyframe_request_sender_; |
89 | 84 |
90 std::map<uint16_t, NackInfo, SeqNumComparator> nack_list_ GUARDED_BY(crit_); | 85 std::map<uint16_t, NackInfo, DescendingSeqNumComp<uint16_t>> nack_list_ |
91 std::set<uint16_t, SeqNumComparator> keyframe_list_ GUARDED_BY(crit_); | 86 GUARDED_BY(crit_); |
| 87 std::set<uint16_t, DescendingSeqNumComp<uint16_t>> keyframe_list_ |
| 88 GUARDED_BY(crit_); |
92 video_coding::Histogram reordering_histogram_ GUARDED_BY(crit_); | 89 video_coding::Histogram reordering_histogram_ GUARDED_BY(crit_); |
93 bool running_ GUARDED_BY(crit_); | 90 bool running_ GUARDED_BY(crit_); |
94 bool initialized_ GUARDED_BY(crit_); | 91 bool initialized_ GUARDED_BY(crit_); |
95 int64_t rtt_ms_ GUARDED_BY(crit_); | 92 int64_t rtt_ms_ GUARDED_BY(crit_); |
96 uint16_t last_seq_num_ GUARDED_BY(crit_); | 93 uint16_t newest_seq_num_ GUARDED_BY(crit_); |
97 int64_t next_process_time_ms_ GUARDED_BY(crit_); | 94 int64_t next_process_time_ms_ GUARDED_BY(crit_); |
98 }; | 95 }; |
99 | 96 |
100 } // namespace webrtc | 97 } // namespace webrtc |
101 | 98 |
102 #endif // WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ | 99 #endif // WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
OLD | NEW |