Adds bytes per second to DataType class.
This is useful for internal calculations in bitrate control code as we
can skip conversion constants.
DataRate Example(TimeDelta time, DataSize size) {
double time_seconds = time.seconds<double>();
double size_bytes = size.bytes<double>();
double rate_bytes_per_sec = size_bytes/time_seconds;
return DataRate::bytes_per_sec(std::max(0.0,rate_bytes_per_sec));
}
Bug: webrtc:9709
Change-Id: I8eefed578b6e8eee67fc36af723216407e0d0323
Reviewed-on: https://webrtc-review.googlesource.com/c/120720
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26488}
This commit is contained in:
parent
813c79bff9
commit
8fe7995045
@ -56,6 +56,11 @@ class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> {
|
||||
return FromValue(bits_per_second);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr DataRate bytes_per_sec(T bytes_per_second) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction<8>(bytes_per_second);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr DataRate kbps(T kilobits_per_sec) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction<1000>(kilobits_per_sec);
|
||||
@ -65,6 +70,10 @@ class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> {
|
||||
return ToValue<T>();
|
||||
}
|
||||
template <typename T = int64_t>
|
||||
constexpr T bytes_per_sec() const {
|
||||
return ToFraction<8, T>();
|
||||
}
|
||||
template <typename T = int64_t>
|
||||
T kbps() const {
|
||||
return ToFraction<1000, T>();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user