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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 running_(true), | 49 running_(true), |
50 initialized_(false), | 50 initialized_(false), |
51 rtt_ms_(kDefaultRttMs), | 51 rtt_ms_(kDefaultRttMs), |
52 last_seq_num_(0), | 52 last_seq_num_(0), |
53 next_process_time_ms_(-1) { | 53 next_process_time_ms_(-1) { |
54 RTC_DCHECK(clock_); | 54 RTC_DCHECK(clock_); |
55 RTC_DCHECK(nack_sender_); | 55 RTC_DCHECK(nack_sender_); |
56 RTC_DCHECK(keyframe_request_sender_); | 56 RTC_DCHECK(keyframe_request_sender_); |
57 } | 57 } |
58 | 58 |
59 void NackModule::OnReceivedPacket(const VCMPacket& packet) { | 59 int NackModule::OnReceivedPacket(const VCMPacket& packet) { |
60 rtc::CritScope lock(&crit_); | 60 rtc::CritScope lock(&crit_); |
61 if (!running_) | 61 if (!running_) |
62 return; | 62 return -1; |
63 uint16_t seq_num = packet.seqNum; | 63 uint16_t seq_num = packet.seqNum; |
64 // TODO(philipel): When the packet includes information whether it is | 64 // TODO(philipel): When the packet includes information whether it is |
65 // retransmitted or not, use that value instead. For | 65 // retransmitted or not, use that value instead. For |
66 // now set it to true, which will cause the reordering | 66 // now set it to true, which will cause the reordering |
67 // statistics to never be updated. | 67 // statistics to never be updated. |
68 bool is_retransmitted = true; | 68 bool is_retransmitted = true; |
69 bool is_keyframe = packet.isFirstPacket && packet.frameType == kVideoFrameKey; | 69 bool is_keyframe = packet.isFirstPacket && packet.frameType == kVideoFrameKey; |
70 | 70 |
71 if (!initialized_) { | 71 if (!initialized_) { |
72 last_seq_num_ = seq_num; | 72 last_seq_num_ = seq_num; |
73 if (is_keyframe) | 73 if (is_keyframe) |
74 keyframe_list_.insert(seq_num); | 74 keyframe_list_.insert(seq_num); |
75 initialized_ = true; | 75 initialized_ = true; |
76 return; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 // Since the |last_seq_num_| is a packet we have actually received we know | |
80 // that packet has never been Nacked. | |
79 if (seq_num == last_seq_num_) | 81 if (seq_num == last_seq_num_) |
80 return; | 82 return 0; |
81 | 83 |
82 if (AheadOf(last_seq_num_, seq_num)) { | 84 if (AheadOf(last_seq_num_, seq_num)) { |
stefan-webrtc
2016/05/12 12:16:53
Should last_seq_num_ be called newest_seq_num_ ins
philipel
2016/05/12 12:55:16
Done.
| |
83 // An out of order packet has been received. | 85 // An out of order packet has been received. |
84 nack_list_.erase(seq_num); | 86 auto nack_list_it = nack_list_.find(seq_num); |
87 if (nack_list_it != nack_list_.end()) { | |
88 int nacks_sent_for_packet = nack_list_it->second.retries; | |
89 nack_list_.erase(nack_list_it); | |
90 return nacks_sent_for_packet; | |
91 } | |
85 if (!is_retransmitted) | 92 if (!is_retransmitted) |
86 UpdateReorderingStatistics(seq_num); | 93 UpdateReorderingStatistics(seq_num); |
stefan-webrtc
2016/05/12 12:16:53
Should we not update reordering statistics if the
philipel
2016/05/12 12:55:16
If the packet isn't in the nack list then the pack
| |
87 return; | 94 return 0; |
88 } else { | 95 } |
89 AddPacketsToNack(last_seq_num_ + 1, seq_num); | 96 AddPacketsToNack(last_seq_num_ + 1, seq_num); |
90 last_seq_num_ = seq_num; | 97 last_seq_num_ = seq_num; |
91 | 98 |
92 // Keep track of new keyframes. | 99 // Keep track of new keyframes. |
93 if (is_keyframe) | 100 if (is_keyframe) |
94 keyframe_list_.insert(seq_num); | 101 keyframe_list_.insert(seq_num); |
95 | 102 |
96 // And remove old ones so we don't accumulate keyframes. | 103 // And remove old ones so we don't accumulate keyframes. |
97 auto it = keyframe_list_.lower_bound(seq_num - kMaxPacketAge); | 104 auto it = keyframe_list_.lower_bound(seq_num - kMaxPacketAge); |
98 if (it != keyframe_list_.begin()) | 105 if (it != keyframe_list_.begin()) |
99 keyframe_list_.erase(keyframe_list_.begin(), it); | 106 keyframe_list_.erase(keyframe_list_.begin(), it); |
100 | 107 |
101 // Are there any nacks that are waiting for this seq_num. | 108 // Are there any nacks that are waiting for this seq_num. |
102 std::vector<uint16_t> nack_batch = GetNackBatch(kSeqNumOnly); | 109 std::vector<uint16_t> nack_batch = GetNackBatch(kSeqNumOnly); |
103 if (!nack_batch.empty()) | 110 if (!nack_batch.empty()) |
104 nack_sender_->SendNack(nack_batch); | 111 nack_sender_->SendNack(nack_batch); |
105 } | 112 |
113 return 0; | |
106 } | 114 } |
107 | 115 |
108 void NackModule::ClearUpTo(uint16_t seq_num) { | 116 void NackModule::ClearUpTo(uint16_t seq_num) { |
109 rtc::CritScope lock(&crit_); | 117 rtc::CritScope lock(&crit_); |
110 nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num)); | 118 nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num)); |
111 keyframe_list_.erase(keyframe_list_.begin(), | 119 keyframe_list_.erase(keyframe_list_.begin(), |
112 keyframe_list_.lower_bound(seq_num)); | 120 keyframe_list_.lower_bound(seq_num)); |
113 } | 121 } |
114 | 122 |
115 void NackModule::UpdateRtt(int64_t rtt_ms) { | 123 void NackModule::UpdateRtt(int64_t rtt_ms) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 reordering_histogram_.Add(diff); | 261 reordering_histogram_.Add(diff); |
254 } | 262 } |
255 | 263 |
256 int NackModule::WaitNumberOfPackets(float probability) const { | 264 int NackModule::WaitNumberOfPackets(float probability) const { |
257 if (reordering_histogram_.NumValues() == 0) | 265 if (reordering_histogram_.NumValues() == 0) |
258 return 0; | 266 return 0; |
259 return reordering_histogram_.InverseCdf(probability); | 267 return reordering_histogram_.InverseCdf(probability); |
260 } | 268 } |
261 | 269 |
262 } // namespace webrtc | 270 } // namespace webrtc |
OLD | NEW |