| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
| 11 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 15 #include "webrtc/system_wrappers/include/clock.h" | 15 #include "webrtc/system_wrappers/include/clock.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 SendTimeHistory::SendTimeHistory(const Clock* clock, | 19 SendTimeHistory::SendTimeHistory(const Clock* clock, |
| 20 int64_t packet_age_limit_ms) | 20 int64_t packet_age_limit_ms) |
| 21 : clock_(clock), packet_age_limit_ms_(packet_age_limit_ms) {} | 21 : clock_(clock), packet_age_limit_ms_(packet_age_limit_ms) {} |
| 22 | 22 |
| 23 SendTimeHistory::~SendTimeHistory() {} | 23 SendTimeHistory::~SendTimeHistory() {} |
| 24 | 24 |
| 25 void SendTimeHistory::Clear() { | 25 void SendTimeHistory::AddAndRemoveOld(const PacketFeedback& packet) { |
| 26 history_.clear(); | |
| 27 } | |
| 28 | |
| 29 void SendTimeHistory::AddAndRemoveOld(uint16_t sequence_number, | |
| 30 size_t payload_size, | |
| 31 const PacedPacketInfo& pacing_info) { | |
| 32 int64_t now_ms = clock_->TimeInMilliseconds(); | 26 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 33 // Remove old. | 27 // Remove old. |
| 34 while (!history_.empty() && | 28 while (!history_.empty() && |
| 35 now_ms - history_.begin()->second.creation_time_ms > | 29 now_ms - history_.begin()->second.creation_time_ms > |
| 36 packet_age_limit_ms_) { | 30 packet_age_limit_ms_) { |
| 37 // TODO(sprang): Warn if erasing (too many) old items? | 31 // TODO(sprang): Warn if erasing (too many) old items? |
| 38 history_.erase(history_.begin()); | 32 history_.erase(history_.begin()); |
| 39 } | 33 } |
| 40 | 34 |
| 41 // Add new. | 35 // Add new. |
| 42 int64_t unwrapped_seq_num = seq_num_unwrapper_.Unwrap(sequence_number); | 36 int64_t unwrapped_seq_num = seq_num_unwrapper_.Unwrap(packet.sequence_number); |
| 43 int64_t creation_time_ms = now_ms; | 37 history_.insert(std::make_pair(unwrapped_seq_num, packet)); |
| 44 constexpr int64_t kNoArrivalTimeMs = -1; // Arrival time is ignored. | |
| 45 constexpr int64_t kNoSendTimeMs = -1; // Send time is set by OnSentPacket. | |
| 46 history_.insert(std::make_pair( | |
| 47 unwrapped_seq_num, | |
| 48 PacketFeedback(creation_time_ms, kNoArrivalTimeMs, kNoSendTimeMs, | |
| 49 sequence_number, payload_size, pacing_info))); | |
| 50 } | 38 } |
| 51 | 39 |
| 52 bool SendTimeHistory::OnSentPacket(uint16_t sequence_number, | 40 bool SendTimeHistory::OnSentPacket(uint16_t sequence_number, |
| 53 int64_t send_time_ms) { | 41 int64_t send_time_ms) { |
| 54 int64_t unwrapped_seq_num = seq_num_unwrapper_.Unwrap(sequence_number); | 42 int64_t unwrapped_seq_num = seq_num_unwrapper_.Unwrap(sequence_number); |
| 55 auto it = history_.find(unwrapped_seq_num); | 43 auto it = history_.find(unwrapped_seq_num); |
| 56 if (it == history_.end()) | 44 if (it == history_.end()) |
| 57 return false; | 45 return false; |
| 58 it->second.send_time_ms = send_time_ms; | 46 it->second.send_time_ms = send_time_ms; |
| 59 return true; | 47 return true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 int64_t arrival_time_ms = packet_feedback->arrival_time_ms; | 60 int64_t arrival_time_ms = packet_feedback->arrival_time_ms; |
| 73 *packet_feedback = it->second; | 61 *packet_feedback = it->second; |
| 74 packet_feedback->arrival_time_ms = arrival_time_ms; | 62 packet_feedback->arrival_time_ms = arrival_time_ms; |
| 75 | 63 |
| 76 if (remove) | 64 if (remove) |
| 77 history_.erase(it); | 65 history_.erase(it); |
| 78 return true; | 66 return true; |
| 79 } | 67 } |
| 80 | 68 |
| 81 } // namespace webrtc | 69 } // namespace webrtc |
| OLD | NEW |