[{"id":20384,"web_url":"https://patchwork.libcamera.org/comment/20384/","msgid":"<CAHW6GYKpwzhbrV_quJvMNFyXNV_Eg6JrgoH6p6YS2-FD5wH0yQ@mail.gmail.com>","date":"2021-10-22T13:13:36","subject":"Re: [libcamera-devel] [PATCH 3/6] pipeline: raspberrypi: Return a\n\tPixelFormat from findBestMode()","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for this patch!\n\nOn Fri, 22 Oct 2021 at 12:55, Naushir Patuck <naush@raspberrypi.com> wrote:\n>\n> It is more convenient to return a PixelFormat from findBestMode(), as the\n> conversions from PixelFormat to V4L2SubdeviceFormat and V4L2DeviceFormat are\n> simpler.\n\nYes indeed, though the PixelFormat still includes packing in an\n\"unhelpful\" way, so there might be even better alternatives?\n\nBest regards\n\nDavid\n\n>\n> Add some internal helpers to perform these conversions.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 73 +++++++++++++------\n>  1 file changed, 52 insertions(+), 21 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 730f1575095c..0f13127a7748 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -50,6 +50,7 @@ namespace {\n>\n>  /* Map of mbus codes to supported sizes reported by the sensor. */\n>  using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n> +using SensorMode = std::pair<PixelFormat, Size>;\n>\n>  SensorFormats populateSensorFormats(std::unique_ptr<CameraSensor> &sensor)\n>  {\n> @@ -61,6 +62,34 @@ SensorFormats populateSensorFormats(std::unique_ptr<CameraSensor> &sensor)\n>         return formats;\n>  }\n>\n> +inline V4L2DeviceFormat toV4L2DeviceFormat(SensorMode &mode)\n> +{\n> +       V4L2DeviceFormat deviceFormat;\n> +\n> +       deviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(mode.first);\n> +       deviceFormat.size = mode.second;\n> +       return deviceFormat;\n> +}\n> +\n> +inline V4L2DeviceFormat toV4L2DeviceFormat(V4L2SubdeviceFormat &format)\n> +{\n> +       V4L2DeviceFormat deviceFormat;\n> +\n> +       deviceFormat.fourcc = BayerFormat::fromMbusCode(format.mbus_code).toV4L2PixelFormat();\n> +       deviceFormat.size = format.size;\n> +       return deviceFormat;\n> +}\n> +\n> +inline V4L2SubdeviceFormat toV4L2SubdeviceFormat(SensorMode &mode)\n> +{\n> +       V4L2SubdeviceFormat subdeviceFormat;\n> +       V4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(mode.first);\n> +\n> +       subdeviceFormat.mbus_code = BayerFormat::fromV4L2PixelFormat(fourcc).toMbusCode();\n> +       subdeviceFormat.size = mode.second;\n> +       return subdeviceFormat;\n> +}\n> +\n>  bool isRaw(PixelFormat &pixFmt)\n>  {\n>         /*\n> @@ -87,10 +116,10 @@ double scoreFormat(double desired, double actual)\n>         return score;\n>  }\n>\n> -V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n> +SensorMode findBestMode(const SensorFormats &formatsMap, const Size &req)\n>  {\n>         double bestScore = std::numeric_limits<double>::max(), score;\n> -       V4L2DeviceFormat bestMode;\n> +       SensorMode bestMode;\n>\n>  #define PENALTY_AR             1500.0\n>  #define PENALTY_8BIT           2000.0\n> @@ -101,8 +130,8 @@ V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n>         /* Calculate the closest/best mode from the user requested size. */\n>         for (const auto &iter : formatsMap) {\n>                 const unsigned int mbus_code = iter.first;\n> -               const V4L2PixelFormat v4l2Format = BayerFormat::fromMbusCode(mbus_code).toV4L2PixelFormat();\n> -               const PixelFormatInfo &info = PixelFormatInfo::info(v4l2Format);\n> +               const PixelFormat format = BayerFormat::fromMbusCode(mbus_code).toPixelFormat();\n> +               const PixelFormatInfo &info = PixelFormatInfo::info(format);\n>\n>                 for (const Size &sz : iter.second) {\n>                         double reqAr = static_cast<double>(req.width) / req.height;\n> @@ -126,12 +155,12 @@ V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const Size &req)\n>\n>                         if (score <= bestScore) {\n>                                 bestScore = score;\n> -                               bestMode.fourcc = v4l2Format;\n> -                               bestMode.size = sz;\n> +                               bestMode.first = format;\n> +                               bestMode.second = sz;\n>                         }\n>\n>                         LOG(RPI, Info) << \"Mode: \" << sz.width << \"x\" << sz.height\n> -                                      << \" fmt \" << v4l2Format.toString()\n> +                                      << \" fmt \" << format.toString()\n>                                        << \" Score: \" << score\n>                                        << \" (best \" << bestScore << \")\";\n>                 }\n> @@ -364,8 +393,9 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                          * Calculate the best sensor mode we can use based on\n>                          * the user request.\n>                          */\n> -                       V4L2DeviceFormat sensorFormat = findBestMode(data_->sensorFormats_, cfg.size);\n> -                       int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat);\n> +                       SensorMode sensorMode = findBestMode(data_->sensorFormats_, cfg.size);\n> +                       V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode);\n> +                       int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat);\n>                         if (ret)\n>                                 return Invalid;\n>\n> @@ -377,7 +407,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                          * fetch the \"native\" (i.e. untransformed) Bayer order,\n>                          * because the sensor may currently be flipped!\n>                          */\n> -                       V4L2PixelFormat fourcc = sensorFormat.fourcc;\n> +                       V4L2PixelFormat fourcc = unicamFormat.fourcc;\n>                         if (data_->flipsAlterBayerOrder_) {\n>                                 BayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc);\n>                                 bayer.order = data_->nativeBayerOrder_;\n> @@ -386,15 +416,15 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                         }\n>\n>                         PixelFormat sensorPixFormat = fourcc.toPixelFormat();\n> -                       if (cfg.size != sensorFormat.size ||\n> +                       if (cfg.size != unicamFormat.size ||\n>                             cfg.pixelFormat != sensorPixFormat) {\n> -                               cfg.size = sensorFormat.size;\n> +                               cfg.size = unicamFormat.size;\n>                                 cfg.pixelFormat = sensorPixFormat;\n>                                 status = Adjusted;\n>                         }\n>\n> -                       cfg.stride = sensorFormat.planes[0].bpl;\n> -                       cfg.frameSize = sensorFormat.planes[0].size;\n> +                       cfg.stride = unicamFormat.planes[0].bpl;\n> +                       cfg.frameSize = unicamFormat.planes[0].size;\n>\n>                         rawCount++;\n>                 } else {\n> @@ -483,7 +513,8 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>  {\n>         RPiCameraData *data = cameraData(camera);\n>         CameraConfiguration *config = new RPiCameraConfiguration(data);\n> -       V4L2DeviceFormat sensorFormat;\n> +       V4L2DeviceFormat unicamFormat;\n> +       SensorMode sensorMode;\n>         unsigned int bufferCount;\n>         PixelFormat pixelFormat;\n>         V4L2VideoDevice::Formats fmts;\n> @@ -498,8 +529,9 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n>                 switch (role) {\n>                 case StreamRole::Raw:\n>                         size = data->sensor_->resolution();\n> -                       sensorFormat = findBestMode(data->sensorFormats_, size);\n> -                       pixelFormat = sensorFormat.fourcc.toPixelFormat();\n> +                       sensorMode = findBestMode(data->sensorFormats_, size);\n> +                       unicamFormat = toV4L2DeviceFormat(sensorMode);\n> +                       pixelFormat = sensorMode.first;\n>                         ASSERT(pixelFormat.isValid());\n>                         bufferCount = 2;\n>                         rawCount++;\n> @@ -609,10 +641,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>         }\n>\n>         /* First calculate the best sensor mode we can use based on the user request. */\n> -       V4L2DeviceFormat unicamFormat = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n> -\n> -       unsigned int mbus_code = BayerFormat::fromV4L2PixelFormat(unicamFormat.fourcc).toMbusCode();\n> -       V4L2SubdeviceFormat sensorFormat { .mbus_code = mbus_code, .size = unicamFormat.size };\n> +       SensorMode sensorMode = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n> +       V4L2SubdeviceFormat sensorFormat = toV4L2SubdeviceFormat(sensorMode);\n> +       V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode);\n>\n>         ret = data->sensor_->setFormat(&sensorFormat);\n>         if (ret)\n> --\n> 2.25.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2ABCBBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Oct 2021 13:13:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F2CAB6012A;\n\tFri, 22 Oct 2021 15:13:48 +0200 (CEST)","from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com\n\t[IPv6:2a00:1450:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 512696012A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 15:13:47 +0200 (CEST)","by mail-wr1-x42b.google.com with SMTP id v17so659378wrv.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 06:13:47 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"WPLjpCLK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=QEf2vo8mk156qjANjBYsj8tw9Jzpwu72f0rhSVAdGOk=;\n\tb=WPLjpCLK6Y9VjUIejGrmy2IQUqhyKFNpzSbe/gFuQdkFdMy9Xb2+5SPwFmQ6aXrhzu\n\tG5MgpWBwdXXMP02xJMq+ZtS0ZU9XpbDUgT+niyM+SeTlPWQDrG9f42S4VV8UctSUpZx4\n\tlYzWq31zP4yFG3gWu3KtEh+TemX0yAnVL1YRvFb5UOacftQEmIlVqnv7Gxbq2JtNOayM\n\tKIwpISeENJdHWSbrmO5NAySaKRmT6TIhAHkZXhdBU3oJ61YVFgKLsiGhY5JSSUYblvje\n\tUdqMG4HlWq0Derk5aqaz0+cKCrGnN2/sZ5Wdn3yL8kO3gSt5DZUkhjKyB+GTmvQniiF8\n\t1/fg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=QEf2vo8mk156qjANjBYsj8tw9Jzpwu72f0rhSVAdGOk=;\n\tb=oxxxE/1IWNCUhsnCzD1lPD09biU33O9Z70tfl+VQjiBJN2GbOFUUh3iELmoysw58N7\n\tOuAJL9giw548vFSNDAJtzzc8Zvx+R46+Y0VcPzDk7Va4KPQ+k9Thv0Wi5SA1LpiWt1iR\n\tdrC6SpHEZPIitfywMbg/L4esrnvdsDOSZvODeSpPK48bGdJLDWGRHgSFkrwjDcuXOKE2\n\tpKZ3e/PgSM9EgKxtDQWRKk+LMuXACSlkmUX7GxqmQjs3VbUTuhrsqx64awZyuQ55axcs\n\tYRKdODjefdtoAW84Fq/Cu1MJWXlc5uODMUoYlUkg0rYP2Zms0rRZtxIlBcGmDvFsFFDf\n\thaRg==","X-Gm-Message-State":"AOAM533iJ+bmjKPe9ZBcC4FA6rWTW6ABGXt8R6c7+qSCAeolfyGLARm2\n\tIriK+ebupwGs6y4rA+ylWxq5v17ES+uQgBDo7ysycJOks1A=","X-Google-Smtp-Source":"ABdhPJzzukbPM7u4GD+rVLtoQh2NC13e09CRkiUS3TBO4cxeQaaf35KcT2NEJ2sNPYnMP05GuDxNMb6SETJUIFpN2xE=","X-Received":"by 2002:adf:e38a:: with SMTP id\n\te10mr1357215wrm.162.1634908426766; \n\tFri, 22 Oct 2021 06:13:46 -0700 (PDT)","MIME-Version":"1.0","References":"<20211022115537.2964533-1-naush@raspberrypi.com>\n\t<20211022115537.2964533-4-naush@raspberrypi.com>","In-Reply-To":"<20211022115537.2964533-4-naush@raspberrypi.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Fri, 22 Oct 2021 14:13:36 +0100","Message-ID":"<CAHW6GYKpwzhbrV_quJvMNFyXNV_Eg6JrgoH6p6YS2-FD5wH0yQ@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 3/6] pipeline: raspberrypi: Return a\n\tPixelFormat from findBestMode()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20390,"web_url":"https://patchwork.libcamera.org/comment/20390/","msgid":"<CAEmqJPrg7OGLdgza7DWJfKmQsnpOeTkgU0GinoxKOY66YA88=Q@mail.gmail.com>","date":"2021-10-22T13:30:04","subject":"Re: [libcamera-devel] [PATCH 3/6] pipeline: raspberrypi: Return a\n\tPixelFormat from findBestMode()","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nThank you for your feedback,\n\nOn Fri, 22 Oct 2021 at 14:13, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> Hi Naush\n>\n> Thanks for this patch!\n>\n> On Fri, 22 Oct 2021 at 12:55, Naushir Patuck <naush@raspberrypi.com>\n> wrote:\n> >\n> > It is more convenient to return a PixelFormat from findBestMode(), as the\n> > conversions from PixelFormat to V4L2SubdeviceFormat and V4L2DeviceFormat\n> are\n> > simpler.\n>\n> Yes indeed, though the PixelFormat still includes packing in an\n> \"unhelpful\" way, so there might be even better alternatives?\n>\n\nYes, as per the comments, on the earlier patch PixelFormat could return a\nV4L2SubdeviceFormat struct to make things more convenient in the code.\n\nRegards,\nNaush\n\n\n\n> Best regards\n>\n> David\n>\n> >\n> > Add some internal helpers to perform these conversions.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 73 +++++++++++++------\n> >  1 file changed, 52 insertions(+), 21 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > index 730f1575095c..0f13127a7748 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -50,6 +50,7 @@ namespace {\n> >\n> >  /* Map of mbus codes to supported sizes reported by the sensor. */\n> >  using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n> > +using SensorMode = std::pair<PixelFormat, Size>;\n> >\n> >  SensorFormats populateSensorFormats(std::unique_ptr<CameraSensor>\n> &sensor)\n> >  {\n> > @@ -61,6 +62,34 @@ SensorFormats\n> populateSensorFormats(std::unique_ptr<CameraSensor> &sensor)\n> >         return formats;\n> >  }\n> >\n> > +inline V4L2DeviceFormat toV4L2DeviceFormat(SensorMode &mode)\n> > +{\n> > +       V4L2DeviceFormat deviceFormat;\n> > +\n> > +       deviceFormat.fourcc =\n> V4L2PixelFormat::fromPixelFormat(mode.first);\n> > +       deviceFormat.size = mode.second;\n> > +       return deviceFormat;\n> > +}\n> > +\n> > +inline V4L2DeviceFormat toV4L2DeviceFormat(V4L2SubdeviceFormat &format)\n> > +{\n> > +       V4L2DeviceFormat deviceFormat;\n> > +\n> > +       deviceFormat.fourcc =\n> BayerFormat::fromMbusCode(format.mbus_code).toV4L2PixelFormat();\n> > +       deviceFormat.size = format.size;\n> > +       return deviceFormat;\n> > +}\n> > +\n> > +inline V4L2SubdeviceFormat toV4L2SubdeviceFormat(SensorMode &mode)\n> > +{\n> > +       V4L2SubdeviceFormat subdeviceFormat;\n> > +       V4L2PixelFormat fourcc =\n> V4L2PixelFormat::fromPixelFormat(mode.first);\n> > +\n> > +       subdeviceFormat.mbus_code =\n> BayerFormat::fromV4L2PixelFormat(fourcc).toMbusCode();\n> > +       subdeviceFormat.size = mode.second;\n> > +       return subdeviceFormat;\n> > +}\n> > +\n> >  bool isRaw(PixelFormat &pixFmt)\n> >  {\n> >         /*\n> > @@ -87,10 +116,10 @@ double scoreFormat(double desired, double actual)\n> >         return score;\n> >  }\n> >\n> > -V4L2DeviceFormat findBestMode(const SensorFormats &formatsMap, const\n> Size &req)\n> > +SensorMode findBestMode(const SensorFormats &formatsMap, const Size\n> &req)\n> >  {\n> >         double bestScore = std::numeric_limits<double>::max(), score;\n> > -       V4L2DeviceFormat bestMode;\n> > +       SensorMode bestMode;\n> >\n> >  #define PENALTY_AR             1500.0\n> >  #define PENALTY_8BIT           2000.0\n> > @@ -101,8 +130,8 @@ V4L2DeviceFormat findBestMode(const SensorFormats\n> &formatsMap, const Size &req)\n> >         /* Calculate the closest/best mode from the user requested size.\n> */\n> >         for (const auto &iter : formatsMap) {\n> >                 const unsigned int mbus_code = iter.first;\n> > -               const V4L2PixelFormat v4l2Format =\n> BayerFormat::fromMbusCode(mbus_code).toV4L2PixelFormat();\n> > -               const PixelFormatInfo &info =\n> PixelFormatInfo::info(v4l2Format);\n> > +               const PixelFormat format =\n> BayerFormat::fromMbusCode(mbus_code).toPixelFormat();\n> > +               const PixelFormatInfo &info =\n> PixelFormatInfo::info(format);\n> >\n> >                 for (const Size &sz : iter.second) {\n> >                         double reqAr = static_cast<double>(req.width) /\n> req.height;\n> > @@ -126,12 +155,12 @@ V4L2DeviceFormat findBestMode(const SensorFormats\n> &formatsMap, const Size &req)\n> >\n> >                         if (score <= bestScore) {\n> >                                 bestScore = score;\n> > -                               bestMode.fourcc = v4l2Format;\n> > -                               bestMode.size = sz;\n> > +                               bestMode.first = format;\n> > +                               bestMode.second = sz;\n> >                         }\n> >\n> >                         LOG(RPI, Info) << \"Mode: \" << sz.width << \"x\" <<\n> sz.height\n> > -                                      << \" fmt \" <<\n> v4l2Format.toString()\n> > +                                      << \" fmt \" << format.toString()\n> >                                        << \" Score: \" << score\n> >                                        << \" (best \" << bestScore << \")\";\n> >                 }\n> > @@ -364,8 +393,9 @@ CameraConfiguration::Status\n> RPiCameraConfiguration::validate()\n> >                          * Calculate the best sensor mode we can use\n> based on\n> >                          * the user request.\n> >                          */\n> > -                       V4L2DeviceFormat sensorFormat =\n> findBestMode(data_->sensorFormats_, cfg.size);\n> > -                       int ret =\n> data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat);\n> > +                       SensorMode sensorMode =\n> findBestMode(data_->sensorFormats_, cfg.size);\n> > +                       V4L2DeviceFormat unicamFormat =\n> toV4L2DeviceFormat(sensorMode);\n> > +                       int ret =\n> data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat);\n> >                         if (ret)\n> >                                 return Invalid;\n> >\n> > @@ -377,7 +407,7 @@ CameraConfiguration::Status\n> RPiCameraConfiguration::validate()\n> >                          * fetch the \"native\" (i.e. untransformed) Bayer\n> order,\n> >                          * because the sensor may currently be flipped!\n> >                          */\n> > -                       V4L2PixelFormat fourcc = sensorFormat.fourcc;\n> > +                       V4L2PixelFormat fourcc = unicamFormat.fourcc;\n> >                         if (data_->flipsAlterBayerOrder_) {\n> >                                 BayerFormat bayer =\n> BayerFormat::fromV4L2PixelFormat(fourcc);\n> >                                 bayer.order = data_->nativeBayerOrder_;\n> > @@ -386,15 +416,15 @@ CameraConfiguration::Status\n> RPiCameraConfiguration::validate()\n> >                         }\n> >\n> >                         PixelFormat sensorPixFormat =\n> fourcc.toPixelFormat();\n> > -                       if (cfg.size != sensorFormat.size ||\n> > +                       if (cfg.size != unicamFormat.size ||\n> >                             cfg.pixelFormat != sensorPixFormat) {\n> > -                               cfg.size = sensorFormat.size;\n> > +                               cfg.size = unicamFormat.size;\n> >                                 cfg.pixelFormat = sensorPixFormat;\n> >                                 status = Adjusted;\n> >                         }\n> >\n> > -                       cfg.stride = sensorFormat.planes[0].bpl;\n> > -                       cfg.frameSize = sensorFormat.planes[0].size;\n> > +                       cfg.stride = unicamFormat.planes[0].bpl;\n> > +                       cfg.frameSize = unicamFormat.planes[0].size;\n> >\n> >                         rawCount++;\n> >                 } else {\n> > @@ -483,7 +513,8 @@ CameraConfiguration\n> *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >  {\n> >         RPiCameraData *data = cameraData(camera);\n> >         CameraConfiguration *config = new RPiCameraConfiguration(data);\n> > -       V4L2DeviceFormat sensorFormat;\n> > +       V4L2DeviceFormat unicamFormat;\n> > +       SensorMode sensorMode;\n> >         unsigned int bufferCount;\n> >         PixelFormat pixelFormat;\n> >         V4L2VideoDevice::Formats fmts;\n> > @@ -498,8 +529,9 @@ CameraConfiguration\n> *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n> >                 switch (role) {\n> >                 case StreamRole::Raw:\n> >                         size = data->sensor_->resolution();\n> > -                       sensorFormat =\n> findBestMode(data->sensorFormats_, size);\n> > -                       pixelFormat =\n> sensorFormat.fourcc.toPixelFormat();\n> > +                       sensorMode = findBestMode(data->sensorFormats_,\n> size);\n> > +                       unicamFormat = toV4L2DeviceFormat(sensorMode);\n> > +                       pixelFormat = sensorMode.first;\n> >                         ASSERT(pixelFormat.isValid());\n> >                         bufferCount = 2;\n> >                         rawCount++;\n> > @@ -609,10 +641,9 @@ int PipelineHandlerRPi::configure(Camera *camera,\n> CameraConfiguration *config)\n> >         }\n> >\n> >         /* First calculate the best sensor mode we can use based on the\n> user request. */\n> > -       V4L2DeviceFormat unicamFormat =\n> findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n> > -\n> > -       unsigned int mbus_code =\n> BayerFormat::fromV4L2PixelFormat(unicamFormat.fourcc).toMbusCode();\n> > -       V4L2SubdeviceFormat sensorFormat { .mbus_code = mbus_code, .size\n> = unicamFormat.size };\n> > +       SensorMode sensorMode = findBestMode(data->sensorFormats_,\n> rawStream ? sensorSize : maxSize);\n> > +       V4L2SubdeviceFormat sensorFormat =\n> toV4L2SubdeviceFormat(sensorMode);\n> > +       V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode);\n> >\n> >         ret = data->sensor_->setFormat(&sensorFormat);\n> >         if (ret)\n> > --\n> > 2.25.1\n> >\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9964EBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Oct 2021 13:30:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CBBEC68F5B;\n\tFri, 22 Oct 2021 15:30:22 +0200 (CEST)","from mail-lf1-x134.google.com (mail-lf1-x134.google.com\n\t[IPv6:2a00:1450:4864:20::134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2037A6012A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 15:30:21 +0200 (CEST)","by mail-lf1-x134.google.com with SMTP id x27so3648834lfu.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 06:30:21 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"CW5DKji9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=WULHbMW0FmAEauYCpDDb4jkYGfBWFb3KK3nx0yTmQKI=;\n\tb=CW5DKji9NYZb3K2if65VHRIYaPrDWy72o2xS6XulI6Bnh76+GxEHvbcAyba0lkh9mC\n\t4jnc0SwwQwiJa+la2fIpw6ezdz45FymIk0SvEnxuqSC+dqpBNGVRARkrMulZr07sbUqn\n\tSwsEOMAmOgU6nT6cLYGUN5QK5OoGEYZ0vkG0U/hpFsz+7YdtVvzFPi2QpNK9CXQqGUVj\n\t+JgFNPNIUQrbMhFGzt/eKUXnRtZbAxqKDT1qvhHVO30GlYlI6XiCRqUjdHSCWN/DvQKn\n\tS4O8dB+hZDkPn2GYjs/345iMksMg/4vCiTfAMWpv87ntPFCQasnmFxXTZDSv7dqxsfYB\n\tb7pA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=WULHbMW0FmAEauYCpDDb4jkYGfBWFb3KK3nx0yTmQKI=;\n\tb=oEL8CFt5T35xJoNem4FZKuqXcMj8gITNAa6zxhC7tas28DVltsmuN6Kosyj07AlJST\n\t3w5PluMF9Izo5Sajh+tdnxH+Td1G8EOodBSUVWHpJRrvx+sbtmv1w0r7e1Y+5AnsV/Om\n\tslU9vCDkWzz56RunJyA+11FEI92qyPr3cQZ6N3M5DnZcCqhJaBNq0CrrfWHv4JnDkUBw\n\tyL6MSP+ryD2+QKn87wMvDIZjfjqw7kgHAk00iJReN/bDgpc5uMqQGMz8BMQomK4AH6t2\n\tWhpVVPJPDhNsa4u3P/U69/WM0T8UGZ8GBPrNsTYekbGSS6YSTLU5M8nY8Mso9w5osfyO\n\th3zQ==","X-Gm-Message-State":"AOAM533CL/rC574ZPUPmNwRgHnWgE2APBcK02whdkrFR3izFRpODR1Cu\n\tT5caO7qIeoab9cBIfj5jgY+IU/+6bHbETfb1p/JN9A==","X-Google-Smtp-Source":"ABdhPJzsoffgXtL79+hu/HJV7t63rfIIvwlhlQqZOvZI0QHeI1MXjO2mtstIBvo0YaLnIfxQO6i+7VIQ64HCPHbRXKk=","X-Received":"by 2002:a05:6512:3709:: with SMTP id\n\tz9mr4889879lfr.122.1634909420482; \n\tFri, 22 Oct 2021 06:30:20 -0700 (PDT)","MIME-Version":"1.0","References":"<20211022115537.2964533-1-naush@raspberrypi.com>\n\t<20211022115537.2964533-4-naush@raspberrypi.com>\n\t<CAHW6GYKpwzhbrV_quJvMNFyXNV_Eg6JrgoH6p6YS2-FD5wH0yQ@mail.gmail.com>","In-Reply-To":"<CAHW6GYKpwzhbrV_quJvMNFyXNV_Eg6JrgoH6p6YS2-FD5wH0yQ@mail.gmail.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 22 Oct 2021 14:30:04 +0100","Message-ID":"<CAEmqJPrg7OGLdgza7DWJfKmQsnpOeTkgU0GinoxKOY66YA88=Q@mail.gmail.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Content-Type":"multipart/alternative; boundary=\"0000000000003f89f905cef10346\"","Subject":"Re: [libcamera-devel] [PATCH 3/6] pipeline: raspberrypi: Return a\n\tPixelFormat from findBestMode()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]