Reland "SeqNumUnwrapper::Unwrap now returns int64_t instead of uint64_t."
This reverts commit b5207b488b035eae4d11dfdcca9526d5a70c9c09. Reason for revert: DecodedFramesHistory has now been updated. Original change's description: > Revert "SeqNumUnwrapper::Unwrap now returns int64_t instead of uint64_t." > > This reverts commit b0f968a761b715da4cf81e4b9c3cab0ccd322cf2. > > Reason for revert: Need to update DecodedFramesHistory to manage negative picture IDs. > > Original change's description: > > SeqNumUnwrapper::Unwrap now returns int64_t instead of uint64_t. > > > > Bug: webrtc:10263 > > Change-Id: Idaeae6be01bd4eba0691226c958d70e114161ffd > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127295 > > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27129} > > TBR=kwiberg@webrtc.org,eladalon@webrtc.org,terelius@webrtc.org,philipel@webrtc.org,kron@webrtc.org > > Change-Id: I529bb0475bd21a80fa244278aff1fd912a85c169 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10263 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127885 > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27135} TBR=kwiberg@webrtc.org,eladalon@webrtc.org,terelius@webrtc.org,philipel@webrtc.org,kron@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10263 Change-Id: Id59e377010b5070dd37a7ece8df79b23af43835a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128568 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27191}
This commit is contained in:
committed by
Commit Bot
parent
c936cb6a86
commit
1f850a6dc7
@ -81,46 +81,35 @@ struct DescendingSeqNumComp {
|
||||
bool operator()(T a, T b) const { return AheadOf<T, M>(b, a); }
|
||||
};
|
||||
|
||||
// A sequencer number unwrapper where the start value of the unwrapped sequence
|
||||
// can be set. The unwrapped value is not allowed to wrap.
|
||||
// A sequence number unwrapper where the first unwrapped value equals the
|
||||
// first value being unwrapped.
|
||||
template <typename T, T M = 0>
|
||||
class SeqNumUnwrapper {
|
||||
// Use '<' instead of rtc::SafeLt to avoid crbug.com/753488
|
||||
static_assert(
|
||||
std::is_unsigned<T>::value &&
|
||||
std::numeric_limits<T>::max() < std::numeric_limits<uint64_t>::max(),
|
||||
"Type unwrapped must be an unsigned integer smaller than uint64_t.");
|
||||
std::numeric_limits<T>::max() < std::numeric_limits<int64_t>::max(),
|
||||
"Type unwrapped must be an unsigned integer smaller than int64_t.");
|
||||
|
||||
public:
|
||||
// We want a default value that is close to 2^62 for a two reasons. Firstly,
|
||||
// we can unwrap wrapping numbers in either direction, and secondly, the
|
||||
// unwrapped numbers can be stored in either int64_t or uint64_t. We also want
|
||||
// the default value to be human readable, which makes a power of 10 suitable.
|
||||
static constexpr uint64_t kDefaultStartValue = 1000000000000000000UL;
|
||||
|
||||
SeqNumUnwrapper() : last_unwrapped_(kDefaultStartValue) {}
|
||||
explicit SeqNumUnwrapper(uint64_t start_at) : last_unwrapped_(start_at) {}
|
||||
|
||||
uint64_t Unwrap(T value) {
|
||||
if (!last_value_)
|
||||
last_value_.emplace(value);
|
||||
|
||||
uint64_t unwrapped = 0;
|
||||
if (AheadOrAt<T, M>(value, *last_value_)) {
|
||||
unwrapped = last_unwrapped_ + ForwardDiff<T, M>(*last_value_, value);
|
||||
RTC_CHECK_GE(unwrapped, last_unwrapped_);
|
||||
int64_t Unwrap(T value) {
|
||||
if (!last_value_) {
|
||||
last_unwrapped_ = {value};
|
||||
} else {
|
||||
unwrapped = last_unwrapped_ - ReverseDiff<T, M>(*last_value_, value);
|
||||
RTC_CHECK_LT(unwrapped, last_unwrapped_);
|
||||
last_unwrapped_ += ForwardDiff<T, M>(*last_value_, value);
|
||||
|
||||
if (!AheadOrAt<T, M>(value, *last_value_)) {
|
||||
constexpr int64_t kBackwardAdjustment =
|
||||
M == 0 ? int64_t{std::numeric_limits<T>::max()} + 1 : M;
|
||||
last_unwrapped_ -= kBackwardAdjustment;
|
||||
}
|
||||
}
|
||||
|
||||
*last_value_ = value;
|
||||
last_unwrapped_ = unwrapped;
|
||||
last_value_ = value;
|
||||
return last_unwrapped_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t last_unwrapped_;
|
||||
int64_t last_unwrapped_ = 0;
|
||||
absl::optional<T> last_value_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user