libcamera: utils: Add helper class for std::chrono::duration
A new utils::Duration class is defined to represent a std::chrono::duration type with double precision nanosecond timebase. Using a double minimises the loss of precision when converting timebases. This helper class may be used by IPAs to represent variables such as frame durations and exposure times. An operator << overload is defined to help with displaying utils::Duration value in stream objects. Currently, this will display the duration value in microseconds. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
committed by
Laurent Pinchart
parent
75c1490827
commit
5055ca747c
@@ -316,8 +316,40 @@ auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
|
||||
}
|
||||
#endif
|
||||
|
||||
class Duration : public std::chrono::duration<double, std::nano>
|
||||
{
|
||||
using BaseDuration = std::chrono::duration<double, std::nano>;
|
||||
|
||||
public:
|
||||
Duration() = default;
|
||||
|
||||
template<typename Rep, typename Period>
|
||||
constexpr Duration(const std::chrono::duration<Rep, Period> &d)
|
||||
: BaseDuration(d)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Period>
|
||||
double get() const
|
||||
{
|
||||
auto const c = std::chrono::duration_cast<std::chrono::duration<double, Period>>(*this);
|
||||
return c.count();
|
||||
}
|
||||
|
||||
explicit constexpr operator bool() const
|
||||
{
|
||||
return *this != BaseDuration::zero();
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace utils */
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os,
|
||||
const utils::Duration &d);
|
||||
#endif
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user