Adds Frequency unit type.

Bug: webrtc:10674
Change-Id: Ic0ddca46d8522d994bbeba072a73836b506fe40f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/138261
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28192}
This commit is contained in:
Sebastian Jansson
2019-06-07 11:05:31 +02:00
committed by Commit Bot
parent d3a4ebe332
commit 26b5e35276
9 changed files with 371 additions and 10 deletions

View File

@ -67,6 +67,26 @@ class UnitBase {
constexpr bool operator<(const Unit_T& other) const {
return value_ < other.value_;
}
Unit_T RoundTo(const Unit_T& resolution) const {
RTC_DCHECK(IsFinite());
RTC_DCHECK(resolution.IsFinite());
RTC_DCHECK_GT(resolution.value_, 0);
return Unit_T((value_ + resolution.value_ / 2) / resolution.value_) *
resolution.value_;
}
Unit_T RoundUpTo(const Unit_T& resolution) const {
RTC_DCHECK(IsFinite());
RTC_DCHECK(resolution.IsFinite());
RTC_DCHECK_GT(resolution.value_, 0);
return Unit_T((value_ + resolution.value_ - 1) / resolution.value_) *
resolution.value_;
}
Unit_T RoundDownTo(const Unit_T& resolution) const {
RTC_DCHECK(IsFinite());
RTC_DCHECK(resolution.IsFinite());
RTC_DCHECK_GT(resolution.value_, 0);
return Unit_T(value_ / resolution.value_) * resolution.value_;
}
protected:
template <int64_t value>