<div dir="ltr"><div dir="ltr">Hi Laurent,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 19 May 2021 at 15:24, Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Naush,<br>
<br>
Thank you for the patch.<br>
<br>
On Tue, May 18, 2021 at 11:07:03AM +0100, Naushir Patuck wrote:<br>
> A new RPiController::Duration typedef is defined to represent a<br>
> std::chrono::duration type with double precision nanosecond timebase<br>
> that will be used throughout. This minimises the loss of precision when<br>
> converting timebases. A function for returning the duration count in any<br>
> timebase is also provided.<br>
> <br>
> An operator << overload is define to help with displaying<br>
> RPiController::Duration value in stream objects.<br>
> <br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> ---<br>
>  src/ipa/raspberrypi/controller/duration.hpp | 33 +++++++++++++++++++++<br>
>  1 file changed, 33 insertions(+)<br>
>  create mode 100644 src/ipa/raspberrypi/controller/duration.hpp<br>
> <br>
> diff --git a/src/ipa/raspberrypi/controller/duration.hpp b/src/ipa/raspberrypi/controller/duration.hpp<br>
> new file mode 100644<br>
> index 000000000000..98aa3d78f52f<br>
> --- /dev/null<br>
> +++ b/src/ipa/raspberrypi/controller/duration.hpp<br>
> @@ -0,0 +1,33 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +/*<br>
> + * Copyright (C) 2021, Raspberry Pi (Trading) Limited<br>
> + *<br>
> + * duration.hpp - Helper macros for std::chrono::duration handling.<br>
> + */<br>
> +#pragma once<br>
> +<br>
> +#include <chrono><br>
> +#include <iomanip><br>
> +#include <iostream><br>
> +<br>
> +namespace RPiController {<br>
> +<br>
> +using Duration = std::chrono::duration<double, std::nano>;<br>
> +<br>
> +// Helper to convert and return the count of any std::chrono::duration type to<br>
> +// another timebase.  Use a double rep type to try and preserve precision.<br>
> +template <typename P, typename T><br>
> +static constexpr double DurationValue(T const &d)<br>
> +{<br>
> +     return std::chrono::duration_cast<std::chrono::duration<double, P>>(d).count();<br>
> +};<br>
> +<br>
> +static inline std::ostream &operator<<(std::ostream &os, const Duration &duration)<br>
> +{<br>
> +        std::streamsize ss = os.precision();<br>
> +        os << std::fixed << std::setprecision(2) << DurationValue<std::micro>(duration) << " us";<br>
> +        os << std::setprecision(ss) << std::defaultfloat;<br>
<br>
This will reset to std::defaultfloat, while the stream may already be in<br>
std::fixed.<br></blockquote><div><br></div><div>Good point, I should save and reapply like I do with precision.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +        return os;<br>
> +}<br>
<br>
Would it be too much yak-shaving to ask for the implementation to be<br>
closer to<br>
<a href="https://en.cppreference.com/w/cpp/chrono/duration/operator_ltlt" rel="noreferrer" target="_blank">https://en.cppreference.com/w/cpp/chrono/duration/operator_ltlt</a>, and<br>
moved to utils.h ? It could be useful more widely in libcamera than just<br>
in the RPi IPA.<br></blockquote><div><br></div><div>Yes, I could look into that.  Did you mean move the whole implementation into utils.h, or</div><div>only the operator <<() bit?  Actually, I would like to make an impactful change in the next</div><div>revision of the series, and replace Duration with a class derived from a std::chrono::duration</div><div>object.  This is a bit neater in terms of encapsulation, and allows me to implement an</div><div>operator bool() method that cleans up the code a bit more.    Functionally, everything else</div><div>remains identical.  Did you want me to put that into utils.h?</div><div><br></div><div>Sorry David, your review for patch 1/4 may need redoing with :-(  </div><div> </div><div>Regards,</div><div>Naush</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> +} // namespace RPiController<br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
</blockquote></div></div>