OLD | NEW |
(Empty) | |
| 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 |
| 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
| 12 #define WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
| 13 |
| 14 #include <map> |
| 15 #include <vector> |
| 16 #include <set> |
| 17 |
| 18 #include "webrtc/base/thread_annotations.h" |
| 19 #include "webrtc/modules/include/module.h" |
| 20 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 21 #include "webrtc/modules/video_coding/packet.h" |
| 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 24 |
| 25 namespace webrtc { |
| 26 |
| 27 class NackModule : public Module { |
| 28 public: |
| 29 NackModule(Clock* clock, |
| 30 VCMNackSender* nack_sender, |
| 31 VCMKeyFrameRequestSender* keyframe_request_sender); |
| 32 |
| 33 void OnReceivedPacket(const VCMPacket& packet); |
| 34 void ClearUpTo(uint16_t seq_num); |
| 35 void UpdateRtt(int64_t rtt_ms); |
| 36 void Stop(); |
| 37 |
| 38 // Module implementation |
| 39 int64_t TimeUntilNextProcess() override; |
| 40 int32_t Process() override; |
| 41 |
| 42 private: |
| 43 // Which fields to consider when deciding |
| 44 // which packet to nack in GetNackBatch. |
| 45 enum NackFilterOptions {kSeqNumOnly, kTimeOnly, kSeqNumAndTime}; |
| 46 |
| 47 static const uint16_t kMaxReorderedPackets = 128; |
| 48 static const uint16_t kNumReorderingBuckets = 5; |
| 49 |
| 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 |
| 52 // we have tried to nack this packet. |
| 53 struct NackInfo { |
| 54 NackInfo(); |
| 55 NackInfo(uint16_t seq_num, uint16_t send_at_seq_num); |
| 56 |
| 57 uint16_t seq_num; |
| 58 uint16_t send_at_seq_num; |
| 59 int64_t sent_at_time; |
| 60 int retries; |
| 61 }; |
| 62 |
| 63 void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end) |
| 64 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 65 |
| 66 // Removes packets from the nack list until the next |
| 67 // keyframe. Returns true if packets were removed. |
| 68 bool RemovePacketsUntilKeyframe() |
| 69 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 70 void RemovePacketFromNack(uint16_t seq_num) |
| 71 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 72 std::vector<uint16_t> GetNackBatch(NackFilterOptions options) |
| 73 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 74 |
| 75 // Update the reordering distribution. |
| 76 void UpdateReorderingStatistics(uint16_t seq_num) |
| 77 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 78 |
| 79 // Returns how many packets we have to wait in order to receive |
| 80 // the packet with probability |probabilty| or higher. |
| 81 int WaitNumberOfPackets(float probability) const |
| 82 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 83 |
| 84 rtc::CriticalSection crit_; |
| 85 Clock* const clock_; |
| 86 VCMNackSender* const nack_sender_; |
| 87 VCMKeyFrameRequestSender* const keyframe_request_sender_; |
| 88 |
| 89 struct SeqNumComparator { |
| 90 SeqNumComparator() { |
| 91 // Alowes the comparator to wrap back one time in order to compare |
| 92 // sequence numbers before an actual wrap has occured. |
| 93 unwrapper_.UpdateLast(0x10000); |
| 94 } |
| 95 bool operator()(uint16_t s1, uint16_t s2) { |
| 96 return unwrapper_.Unwrap(s1) < unwrapper_.Unwrap(s2); |
| 97 } |
| 98 SequenceNumberUnwrapper unwrapper_; |
| 99 }; |
| 100 std::map<int16_t, NackInfo, SeqNumComparator> nack_list_ GUARDED_BY(crit_); |
| 101 std::set<int16_t, SeqNumComparator> keyframe_list_ GUARDED_BY(crit_); |
| 102 bool running_ GUARDED_BY(crit_); |
| 103 bool initialized_ GUARDED_BY(crit_); |
| 104 int64_t rtt_ms_ GUARDED_BY(crit_); |
| 105 uint16_t last_seq_num_ GUARDED_BY(crit_); |
| 106 int64_t next_process_time_ms_ GUARDED_BY(crit_); |
| 107 |
| 108 int reordering_index_ GUARDED_BY(crit_); |
| 109 int reordering_count_ GUARDED_BY(crit_); |
| 110 int reordering_occurences_[kMaxReorderedPackets] GUARDED_BY(crit_); |
| 111 int reordering_buckets_[kNumReorderingBuckets] GUARDED_BY(crit_); |
| 112 }; |
| 113 |
| 114 } // namespace webrtc |
| 115 |
| 116 #endif // WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
OLD | NEW |