Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(809)

Side by Side Diff: webrtc/modules/video_coding/sequence_number_util.h

Issue 2985283002: Unwrap picture ids in the RtpFrameReferencerFinder. (Closed)
Patch Set: Feedback Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // can be set. The unwrapped value is not allowed to wrap. 84 // can be set. The unwrapped value is not allowed to wrap.
85 template <typename T, T M = 0> 85 template <typename T, T M = 0>
86 class SeqNumUnwrapper { 86 class SeqNumUnwrapper {
87 // Use '<' instead of rtc::SafeLt to avoid crbug.com/753488 87 // Use '<' instead of rtc::SafeLt to avoid crbug.com/753488
88 static_assert( 88 static_assert(
89 std::is_unsigned<T>::value && 89 std::is_unsigned<T>::value &&
90 std::numeric_limits<T>::max() < std::numeric_limits<uint64_t>::max(), 90 std::numeric_limits<T>::max() < std::numeric_limits<uint64_t>::max(),
91 "Type unwrapped must be an unsigned integer smaller than uint64_t."); 91 "Type unwrapped must be an unsigned integer smaller than uint64_t.");
92 92
93 public: 93 public:
94 SeqNumUnwrapper() : last_unwrapped_(0) {} 94 // We want a value that is close to 2^63 for two reasons. Firstly, we
95 // can unwrap wrapping numbers in either direction, and secondly, we avoid
96 // causing a crash on bad input. We also want the default value to be somewhat
97 // human readable, a power of 10 for example.
98 static constexpr uint64_t kDefaultStartValue = 10000000000000000000UL;
99
100 SeqNumUnwrapper() : last_unwrapped_(kDefaultStartValue) {}
95 explicit SeqNumUnwrapper(uint64_t start_at) : last_unwrapped_(start_at) {} 101 explicit SeqNumUnwrapper(uint64_t start_at) : last_unwrapped_(start_at) {}
96 102
97 uint64_t Unwrap(T value) { 103 uint64_t Unwrap(T value) {
98 if (!last_value_) 104 if (!last_value_)
99 last_value_.emplace(value); 105 last_value_.emplace(value);
100 106
101 uint64_t unwrapped = 0; 107 uint64_t unwrapped = 0;
102 if (AheadOrAt<T, M>(value, *last_value_)) { 108 if (AheadOrAt<T, M>(value, *last_value_)) {
103 unwrapped = last_unwrapped_ + ForwardDiff<T, M>(*last_value_, value); 109 unwrapped = last_unwrapped_ + ForwardDiff<T, M>(*last_value_, value);
104 RTC_CHECK_GE(unwrapped, last_unwrapped_); 110 RTC_CHECK_GE(unwrapped, last_unwrapped_);
105 } else { 111 } else {
106 unwrapped = last_unwrapped_ - ReverseDiff<T, M>(*last_value_, value); 112 unwrapped = last_unwrapped_ - ReverseDiff<T, M>(*last_value_, value);
107 RTC_CHECK_LT(unwrapped, last_unwrapped_); 113 RTC_CHECK_LT(unwrapped, last_unwrapped_);
108 } 114 }
109 115
110 *last_value_ = value; 116 *last_value_ = value;
111 last_unwrapped_ = unwrapped; 117 last_unwrapped_ = unwrapped;
112 return last_unwrapped_; 118 return last_unwrapped_;
113 } 119 }
114 120
115 private: 121 private:
116 uint64_t last_unwrapped_; 122 uint64_t last_unwrapped_;
117 rtc::Optional<T> last_value_; 123 rtc::Optional<T> last_value_;
118 }; 124 };
119 125
120 } // namespace webrtc 126 } // namespace webrtc
121 127
122 #endif // WEBRTC_MODULES_VIDEO_CODING_SEQUENCE_NUMBER_UTIL_H_ 128 #endif // WEBRTC_MODULES_VIDEO_CODING_SEQUENCE_NUMBER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698