[libcamera-devel] [PATCH 1/4] ipa: raspberrypi: Add helper macros for std::chrono::duration

Naushir Patuck naush at raspberrypi.com
Wed May 19 12:50:22 CEST 2021


Hi David,

Thank you for your review feedback.

On Wed, 19 May 2021 at 11:38, David Plowman <david.plowman at raspberrypi.com>
wrote:

> Hi Naush
>
> Thank you for this patch.
>
> On Tue, 18 May 2021 at 11:09, Naushir Patuck <naush at raspberrypi.com>
> wrote:
> >
> > A new RPiController::Duration typedef is defined to represent a
> > std::chrono::duration type with double precision nanosecond timebase
> > that will be used throughout. This minimises the loss of precision when
> > converting timebases. A function for returning the duration count in any
> > timebase is also provided.
> >
> > An operator << overload is define to help with displaying
> > RPiController::Duration value in stream objects.
> >
> > Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
> > ---
> >  src/ipa/raspberrypi/controller/duration.hpp | 33 +++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> >  create mode 100644 src/ipa/raspberrypi/controller/duration.hpp
> >
> > diff --git a/src/ipa/raspberrypi/controller/duration.hpp
> b/src/ipa/raspberrypi/controller/duration.hpp
> > new file mode 100644
> > index 000000000000..98aa3d78f52f
> > --- /dev/null
> > +++ b/src/ipa/raspberrypi/controller/duration.hpp
> > @@ -0,0 +1,33 @@
> > +/* SPDX-License-Identifier: BSD-2-Clause */
> > +/*
> > + * Copyright (C) 2021, Raspberry Pi (Trading) Limited
> > + *
> > + * duration.hpp - Helper macros for std::chrono::duration handling.
> > + */
> > +#pragma once
> > +
> > +#include <chrono>
> > +#include <iomanip>
> > +#include <iostream>
> > +
> > +namespace RPiController {
> > +
> > +using Duration = std::chrono::duration<double, std::nano>;
> > +
> > +// Helper to convert and return the count of any std::chrono::duration
> type to
> > +// another timebase.  Use a double rep type to try and preserve
> precision.
> > +template <typename P, typename T>
> > +static constexpr double DurationValue(T const &d)
> > +{
> > +       return std::chrono::duration_cast<std::chrono::duration<double,
> P>>(d).count();
> > +};
> > +
> > +static inline std::ostream &operator<<(std::ostream &os, const Duration
> &duration)
> > +{
> > +        std::streamsize ss = os.precision();
> > +        os << std::fixed << std::setprecision(2) <<
> DurationValue<std::micro>(duration) << " us";
>
> I suppose I wonder slightly why we change the precision, I assume the
> output is just a bit tidier like that? And a space before the "us"? I
> guess, why not!
>

Yes, I did not want more than 2 decimal places of precision in the output.
I can remove the space
before the "us" in the next revision.

Regards,
Naush


>
> Reviewed-by: David Plowman <david.plowman at raspberrypi.com>
>
> Thanks
> David
>
> > +        os << std::setprecision(ss) << std::defaultfloat;
> > +        return os;
> > +}
> > +
> > +} // namespace RPiController
> > --
> > 2.25.1
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20210519/815876fa/attachment.htm>


More information about the libcamera-devel mailing list