breadcast/breadcast-caststream-sys/vendor/openscreen/util/integer_division.h
Breadway 8c745d18e0
Some checks failed
dev release / build (push) Failing after 12s
Implement Cast Streaming mirroring, DLNA casting, daemon+GUI, and breadd integration
Builds out the full v1 scope: a vendored+patched openscreen subset for
low-latency Cast Streaming (Mirroring receiver 0F5096E8) alongside the
existing Cast V2/HLS and new DLNA/AVTransport casting paths, breadcastd's
Idle/Casting state machine with a private IPC socket, the breadcast GTK4
popup as a thin IPC client, and bread.cast.*/bread.command.cast.* breadd
integration (device discovery, start/stop, mirroring lifecycle events).
Also adds bakery/systemd/Forgejo CI packaging.

Validated end-to-end against a real Chromecast/Google TV: negotiated
Cast Streaming session, live pipeline playback, and daemon+GUI click-to-cast/
stop through the actual popup.
2026-08-03 09:07:21 +08:00

67 lines
2.2 KiB
C++

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UTIL_INTEGER_DIVISION_H_
#define UTIL_INTEGER_DIVISION_H_
#include <type_traits>
namespace openscreen {
// Returns CEIL(num ÷ denom). `denom` must not equal zero. This function is
// compatible with any integer-like type, including the integer-based
// std::chrono duration types.
//
// Optimization note: See DividePositivesRoundingUp().
template <typename Integer>
constexpr auto DivideRoundingUp(Integer num, Integer denom) {
if (denom < Integer{0}) {
num *= -1;
denom *= -1;
}
if (num < Integer{0}) {
return num / denom;
}
return (num + denom - Integer{1}) / denom;
}
// Same as DivideRoundingUp(), except is more-efficient for hot code paths that
// know `num` is always greater or equal to zero, and `denom` is always greater
// than zero.
template <typename Integer>
constexpr Integer DividePositivesRoundingUp(Integer num, Integer denom) {
return DivideRoundingUp<typename std::make_unsigned<Integer>::type>(num,
denom);
}
// Divides `num` by `denom`, and rounds to the nearest integer (exactly halfway
// between integers will round to the higher integer). This function is
// compatible with any integer-like type, including the integer-based
// std::chrono duration types.
//
// Optimization note: See DividePositivesRoundingNearest().
template <typename Integer>
constexpr auto DivideRoundingNearest(Integer num, Integer denom) {
if (denom < Integer{0}) {
num *= -1;
denom *= -1;
}
if (num < Integer{0}) {
return (num - ((denom - Integer{1}) / 2)) / denom;
}
return (num + (denom / 2)) / denom;
}
// Same as DivideRoundingNearest(), except is more-efficient for hot code paths
// that know `num` is always greater or equal to zero, and `denom` is always
// greater than zero.
template <typename Integer>
constexpr Integer DividePositivesRoundingNearest(Integer num, Integer denom) {
return DivideRoundingNearest<typename std::make_unsigned<Integer>::type>(
num, denom);
}
} // namespace openscreen
#endif // UTIL_INTEGER_DIVISION_H_