/* * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
namespace webrtc { // DataRate is a class that represents a given data rate. This can be used to // represent bandwidth, encoding bitrate, etc. The internal storage is bits per // second (bps). class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> { public: template <typename T> static constexpr DataRate BitsPerSec(T value) {
static_assert(std::is_arithmetic<T>::value, ""); return FromValue(value);
} template <typename T> static constexpr DataRate BytesPerSec(T value) {
static_assert(std::is_arithmetic<T>::value, ""); return FromFraction(8, value);
} template <typename T> static constexpr DataRate KilobitsPerSec(T value) {
static_assert(std::is_arithmetic<T>::value, ""); return FromFraction(1000, value);
} static constexpr DataRate Infinity() { return PlusInfinity(); }
template <typename T = int64_t>
constexpr T bps() const { return ToValue<T>();
} template <typename T = int64_t>
constexpr T bytes_per_sec() const { return ToFraction<8, T>();
} template <typename T = int64_t>
constexpr T kbps() const { return ToFraction<1000, T>();
}
constexpr int64_t bps_or(int64_t fallback_value) const { return ToValueOr(fallback_value);
}
constexpr int64_t kbps_or(int64_t fallback_value) const { return ToFractionOr<1000>(fallback_value);
}
private: // Bits per second used internally to simplify debugging by making the value // more recognizable. friendclass rtc_units_impl::UnitBase<DataRate>; using RelativeUnit::RelativeUnit; static constexpr bool one_sided = true;
};
namespace data_rate_impl { inline constexpr int64_t Microbits(const DataSize& size) {
constexpr int64_t kMaxBeforeConversion =
std::numeric_limits<int64_t>::max() / 8000000;
RTC_DCHECK_LE(size.bytes(), kMaxBeforeConversion)
<< "size is too large to be expressed in microbits"; return size.bytes() * 8000000;
}
inline constexpr int64_t MillibytePerSec(const DataRate& size) {
constexpr int64_t kMaxBeforeConversion =
std::numeric_limits<int64_t>::max() / (1000 / 8);
RTC_DCHECK_LE(size.bps(), kMaxBeforeConversion)
<< "rate is too large to be expressed in microbytes per second"; return size.bps() * (1000 / 8);
}
} // namespace data_rate_impl
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.