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/criticalsection.h" |
| 19 #include "webrtc/base/thread_annotations.h" |
| 20 #include "webrtc/modules/include/module.h" |
| 21 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 22 #include "webrtc/modules/video_coding/packet.h" |
| 23 #include "webrtc/modules/video_coding/histogram.h" |
| 24 #include "webrtc/system_wrappers/include/clock.h" |
| 25 |
| 26 namespace webrtc { |
| 27 |
| 28 class NackModule : public Module { |
| 29 public: |
| 30 NackModule(Clock* clock, |
| 31 NackSender* nack_sender, |
| 32 KeyFrameRequestSender* keyframe_request_sender); |
| 33 |
| 34 void OnReceivedPacket(const VCMPacket& packet); |
| 35 void ClearUpTo(uint16_t seq_num); |
| 36 void UpdateRtt(int64_t rtt_ms); |
| 37 void Stop(); |
| 38 |
| 39 // Module implementation |
| 40 int64_t TimeUntilNextProcess() override; |
| 41 void Process() override; |
| 42 |
| 43 private: |
| 44 // Which fields to consider when deciding which packet to nack in |
| 45 // GetNackBatch. |
| 46 enum NackFilterOptions { kSeqNumOnly, kTimeOnly, kSeqNumAndTime }; |
| 47 |
| 48 // This class holds the sequence number of the packet that is in the nack list |
| 49 // as well as the meta data about when it should be nacked and how many times |
| 50 // we have tried to nack this packet. |
| 51 struct NackInfo { |
| 52 NackInfo(); |
| 53 NackInfo(uint16_t seq_num, uint16_t send_at_seq_num); |
| 54 |
| 55 uint16_t seq_num; |
| 56 uint16_t send_at_seq_num; |
| 57 int64_t sent_at_time; |
| 58 int retries; |
| 59 }; |
| 60 |
| 61 struct SeqNumComparator { |
| 62 bool operator()(uint16_t s1, uint16_t s2) { |
| 63 return IsNewerSequenceNumber(s2, s1); |
| 64 } |
| 65 }; |
| 66 |
| 67 void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end) |
| 68 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 69 |
| 70 // Removes packets from the nack list until the next keyframe. Returns true |
| 71 // if packets were removed. |
| 72 bool RemovePacketsUntilKeyFrame() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 73 std::vector<uint16_t> GetNackBatch(NackFilterOptions options) |
| 74 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 75 |
| 76 // Update the reordering distribution. |
| 77 void UpdateReorderingStatistics(uint16_t seq_num) |
| 78 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 79 |
| 80 // Returns how many packets we have to wait in order to receive the packet |
| 81 // with probability |probabilty| or higher. |
| 82 int WaitNumberOfPackets(float probability) const |
| 83 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 84 |
| 85 rtc::CriticalSection crit_; |
| 86 Clock* const clock_; |
| 87 NackSender* const nack_sender_; |
| 88 KeyFrameRequestSender* const keyframe_request_sender_; |
| 89 |
| 90 std::map<uint16_t, NackInfo, SeqNumComparator> nack_list_ GUARDED_BY(crit_); |
| 91 std::set<uint16_t, SeqNumComparator> keyframe_list_ GUARDED_BY(crit_); |
| 92 video_coding::Histogram reordering_histogram_ GUARDED_BY(crit_); |
| 93 bool running_ GUARDED_BY(crit_); |
| 94 bool initialized_ GUARDED_BY(crit_); |
| 95 int64_t rtt_ms_ GUARDED_BY(crit_); |
| 96 uint16_t last_seq_num_ GUARDED_BY(crit_); |
| 97 int64_t next_process_time_ms_ GUARDED_BY(crit_); |
| 98 }; |
| 99 |
| 100 } // namespace webrtc |
| 101 |
| 102 #endif // WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
OLD | NEW |