From 8fe7995045197e9f332a0359ef833a30d5831c74 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Thu, 31 Jan 2019 11:09:35 +0100 Subject: [PATCH] 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 size_bytes = size.bytes(); 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 Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#26488} --- api/units/data_rate.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/units/data_rate.h b/api/units/data_rate.h index 8a3836d0b7..9b09aa92cd 100644 --- a/api/units/data_rate.h +++ b/api/units/data_rate.h @@ -56,6 +56,11 @@ class DataRate final : public rtc_units_impl::RelativeUnit { return FromValue(bits_per_second); } template + static constexpr DataRate bytes_per_sec(T bytes_per_second) { + static_assert(std::is_arithmetic::value, ""); + return FromFraction<8>(bytes_per_second); + } + template static constexpr DataRate kbps(T kilobits_per_sec) { static_assert(std::is_arithmetic::value, ""); return FromFraction<1000>(kilobits_per_sec); @@ -65,6 +70,10 @@ class DataRate final : public rtc_units_impl::RelativeUnit { return ToValue(); } template + constexpr T bytes_per_sec() const { + return ToFraction<8, T>(); + } + template T kbps() const { return ToFraction<1000, T>(); }