[{"id":20565,"web_url":"https://patchwork.libcamera.org/comment/20565/","msgid":"<163533800433.1184428.1527433292868489588@Monstersaurus>","date":"2021-10-27T12:33:24","subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2021-10-27 10:28:03)\n> Sensor flips might change the Bayer order of the requested format. The existing\n> code would set a sensor format along with the appropriate Unicam and ISP input\n> formats, but reset the latter two on start() once the flips had been requested.\n> \n> We can now set the sensor flips just before we set the sensor mode in\n> configure(), thereby not needing the second pair of format sets in start().\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nWill the user be able to flip at runtime? I suspect they can't currently\nanyway so it doesn't matter, but anyway, I can't see anything wrong with\nthis:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 56 ++++++-------------\n>  1 file changed, 16 insertions(+), 40 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 52521857b61c..eaa2676b891e 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -657,16 +657,28 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>                 }\n>         }\n>  \n> +       /*\n> +        * Configure the H/V flip controls based on the combination of\n> +        * the sensor and user transform.\n> +        */\n> +       if (data->supportsFlips_) {\n> +               const RPiCameraConfiguration *rpiConfig =\n> +                       static_cast<const RPiCameraConfiguration *>(config);\n> +               ControlList controls;\n> +\n> +               controls.set(V4L2_CID_HFLIP,\n> +                            static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> +               controls.set(V4L2_CID_VFLIP,\n> +                            static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> +               data->setSensorControls(controls);\n> +       }\n> +\n>         /* First calculate the best sensor mode we can use based on the user request. */\n>         V4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n>         ret = data->sensor_->setFormat(&sensorFormat);\n>         if (ret)\n>                 return ret;\n>  \n> -       /*\n> -        * Unicam image output format. The ISP input format gets set at start,\n> -        * just in case we have swapped bayer orders due to flips.\n> -        */\n>         V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, packing);\n>         ret = data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat);\n>         if (ret)\n> @@ -676,10 +688,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>                        << \" - Selected sensor format: \" << sensorFormat.toString()\n>                        << \" - Selected unicam format: \" << unicamFormat.toString();\n>  \n> -       /*\n> -        * This format may be reset on start() if the bayer order has changed\n> -        * because of flips in the sensor.\n> -        */\n>         ret = data->isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n>         if (ret)\n>                 return ret;\n> @@ -902,23 +910,6 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)\n>                 return ret;\n>         }\n>  \n> -       /*\n> -        * IPA configure may have changed the sensor flips - hence the bayer\n> -        * order. Get the sensor format and set the ISP input now.\n> -        */\n> -       V4L2SubdeviceFormat sensorFormat;\n> -       data->sensor_->device()->getFormat(0, &sensorFormat);\n> -\n> -       V4L2DeviceFormat ispFormat;\n> -       ispFormat.fourcc = mbusCodeToBayerFormat(sensorFormat.mbus_code).toV4L2PixelFormat();\n> -       ispFormat.size = sensorFormat.size;\n> -\n> -       ret = data->isp_[Isp::Input].dev()->setFormat(&ispFormat);\n> -       if (ret) {\n> -               stop(camera);\n> -               return ret;\n> -       }\n> -\n>         /* Enable SOF event generation. */\n>         data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n>  \n> @@ -1332,10 +1323,6 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig)\n>  \n>  int RPiCameraData::configureIPA(const CameraConfiguration *config)\n>  {\n> -       /* We know config must be an RPiCameraConfiguration. */\n> -       const RPiCameraConfiguration *rpiConfig =\n> -               static_cast<const RPiCameraConfiguration *>(config);\n> -\n>         std::map<unsigned int, IPAStream> streamConfig;\n>         std::map<unsigned int, ControlInfoMap> entityControls;\n>         ipa::RPi::IPAConfig ipaConfig;\n> @@ -1386,17 +1373,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n>                 return -EPIPE;\n>         }\n>  \n> -       /*\n> -        * Configure the H/V flip controls based on the combination of\n> -        * the sensor and user transform.\n> -        */\n> -       if (supportsFlips_) {\n> -               controls.set(V4L2_CID_HFLIP,\n> -                            static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> -               controls.set(V4L2_CID_VFLIP,\n> -                            static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> -       }\n> -\n>         if (!controls.empty())\n>                 setSensorControls(controls);\n>  \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 17284BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Oct 2021 12:33:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C9B906487F;\n\tWed, 27 Oct 2021 14:33:28 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 87C5E60123\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Oct 2021 14:33:27 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 34B15596;\n\tWed, 27 Oct 2021 14:33:27 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ulmTtEOI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1635338007;\n\tbh=2KmZhIeI3fKUbBRGtm4RrZWHt/RPDY86PYrtYP8gj64=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=ulmTtEOIUav0m8H/Qj2vTKLiZejWsnN3P4CI2OrgR9nyS6cSgtGz/u5kR428UiTRL\n\tQw8r7uEIk8COu/WBNpsZazHBPDJ10dVi9c96qBYOUc+jhrasRr/N8AUbyB1KKPy9AJ\n\taAV7N1CvO2MzZ3Z7/Rwh2Tniry+pqO8Y5EAQbMUc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211027092803.3671096-10-naush@raspberrypi.com>","References":"<20211027092803.3671096-1-naush@raspberrypi.com>\n\t<20211027092803.3671096-10-naush@raspberrypi.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 27 Oct 2021 13:33:24 +0100","Message-ID":"<163533800433.1184428.1527433292868489588@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20573,"web_url":"https://patchwork.libcamera.org/comment/20573/","msgid":"<CAEmqJPq8Xx7=7OSjuqn_Z7xNde=DxGp+fXj+JOWAbKkZoWuTRA@mail.gmail.com>","date":"2021-10-27T12:41:48","subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Kieran,\n\nThank you for your feedback,\n\nOn Wed, 27 Oct 2021 at 13:33, Kieran Bingham <\nkieran.bingham@ideasonboard.com> wrote:\n\n> Quoting Naushir Patuck (2021-10-27 10:28:03)\n> > Sensor flips might change the Bayer order of the requested format. The\n> existing\n> > code would set a sensor format along with the appropriate Unicam and ISP\n> input\n> > formats, but reset the latter two on start() once the flips had been\n> requested.\n> >\n> > We can now set the sensor flips just before we set the sensor mode in\n> > configure(), thereby not needing the second pair of format sets in\n> start().\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n>\n> Will the user be able to flip at runtime? I suspect they can't currently\n> anyway so it doesn't matter, but anyway, I can't see anything wrong with\n> this:\n>\n\nNo runtime changes of flips are not possible.  That would be too\ncomplicated to deal with :-)\n\nRegards,\nNaush\n\n\n>\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> > ---\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 56 ++++++-------------\n> >  1 file changed, 16 insertions(+), 40 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > index 52521857b61c..eaa2676b891e 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -657,16 +657,28 @@ int PipelineHandlerRPi::configure(Camera *camera,\n> CameraConfiguration *config)\n> >                 }\n> >         }\n> >\n> > +       /*\n> > +        * Configure the H/V flip controls based on the combination of\n> > +        * the sensor and user transform.\n> > +        */\n> > +       if (data->supportsFlips_) {\n> > +               const RPiCameraConfiguration *rpiConfig =\n> > +                       static_cast<const RPiCameraConfiguration\n> *>(config);\n> > +               ControlList controls;\n> > +\n> > +               controls.set(V4L2_CID_HFLIP,\n> > +\n> static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> > +               controls.set(V4L2_CID_VFLIP,\n> > +\n> static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> > +               data->setSensorControls(controls);\n> > +       }\n> > +\n> >         /* First calculate the best sensor mode we can use based on the\n> user request. */\n> >         V4L2SubdeviceFormat sensorFormat =\n> findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n> >         ret = data->sensor_->setFormat(&sensorFormat);\n> >         if (ret)\n> >                 return ret;\n> >\n> > -       /*\n> > -        * Unicam image output format. The ISP input format gets set at\n> start,\n> > -        * just in case we have swapped bayer orders due to flips.\n> > -        */\n> >         V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat,\n> packing);\n> >         ret =\n> data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat);\n> >         if (ret)\n> > @@ -676,10 +688,6 @@ int PipelineHandlerRPi::configure(Camera *camera,\n> CameraConfiguration *config)\n> >                        << \" - Selected sensor format: \" <<\n> sensorFormat.toString()\n> >                        << \" - Selected unicam format: \" <<\n> unicamFormat.toString();\n> >\n> > -       /*\n> > -        * This format may be reset on start() if the bayer order has\n> changed\n> > -        * because of flips in the sensor.\n> > -        */\n> >         ret = data->isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n> >         if (ret)\n> >                 return ret;\n> > @@ -902,23 +910,6 @@ int PipelineHandlerRPi::start(Camera *camera, const\n> ControlList *controls)\n> >                 return ret;\n> >         }\n> >\n> > -       /*\n> > -        * IPA configure may have changed the sensor flips - hence the\n> bayer\n> > -        * order. Get the sensor format and set the ISP input now.\n> > -        */\n> > -       V4L2SubdeviceFormat sensorFormat;\n> > -       data->sensor_->device()->getFormat(0, &sensorFormat);\n> > -\n> > -       V4L2DeviceFormat ispFormat;\n> > -       ispFormat.fourcc =\n> mbusCodeToBayerFormat(sensorFormat.mbus_code).toV4L2PixelFormat();\n> > -       ispFormat.size = sensorFormat.size;\n> > -\n> > -       ret = data->isp_[Isp::Input].dev()->setFormat(&ispFormat);\n> > -       if (ret) {\n> > -               stop(camera);\n> > -               return ret;\n> > -       }\n> > -\n> >         /* Enable SOF event generation. */\n> >         data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n> >\n> > @@ -1332,10 +1323,6 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig\n> *sensorConfig)\n> >\n> >  int RPiCameraData::configureIPA(const CameraConfiguration *config)\n> >  {\n> > -       /* We know config must be an RPiCameraConfiguration. */\n> > -       const RPiCameraConfiguration *rpiConfig =\n> > -               static_cast<const RPiCameraConfiguration *>(config);\n> > -\n> >         std::map<unsigned int, IPAStream> streamConfig;\n> >         std::map<unsigned int, ControlInfoMap> entityControls;\n> >         ipa::RPi::IPAConfig ipaConfig;\n> > @@ -1386,17 +1373,6 @@ int RPiCameraData::configureIPA(const\n> CameraConfiguration *config)\n> >                 return -EPIPE;\n> >         }\n> >\n> > -       /*\n> > -        * Configure the H/V flip controls based on the combination of\n> > -        * the sensor and user transform.\n> > -        */\n> > -       if (supportsFlips_) {\n> > -               controls.set(V4L2_CID_HFLIP,\n> > -\n> static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> > -               controls.set(V4L2_CID_VFLIP,\n> > -\n> static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> > -       }\n> > -\n> >         if (!controls.empty())\n> >                 setSensorControls(controls);\n> >\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 6FC67BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Oct 2021 12:42:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 33DA564884;\n\tWed, 27 Oct 2021 14:42:06 +0200 (CEST)","from mail-lf1-x131.google.com (mail-lf1-x131.google.com\n\t[IPv6:2a00:1450:4864:20::131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E7A4860123\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Oct 2021 14:42:04 +0200 (CEST)","by mail-lf1-x131.google.com with SMTP id j2so5926300lfg.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Oct 2021 05:42:04 -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=\"KGw5Q4H2\"; 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=DG6v3PnWlq2pZ/db3nvRYPmQ9GaGQ4Rmmh26UPT5OVo=;\n\tb=KGw5Q4H2m2XzC8nSSkx7W4nmIFtk8Z0SIQ17/879CSoQNw3ryM+HtCWR0Ggm8mqbSp\n\tuqNDxfGzR3uI8OKglbzcJ3HVKLHlQsz9b9DOqgve2MBGqqsnlcjGovDMc/zh/ilNrp+l\n\tXNZo2Odpd7+D2PUOxdC/9lvAYTYfk2uMXNG7/vPXtS+LH4le9ptXb4QIg/fBdBlLhGdo\n\tfg+rz7OKQL/MaFND2ijf4shpUfZzmAFn/oYGPwkVZLs7TOwsUumXyI4V8xFuc4fM8hhn\n\t68jhNwgvNiO2iwF4DwzcVqh6B5m418MIKZbgwQHZPfe0SPIcdoxKk4IQ/SoWVSI36VHd\n\tRw4w==","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=DG6v3PnWlq2pZ/db3nvRYPmQ9GaGQ4Rmmh26UPT5OVo=;\n\tb=uRf2H9hsUb02D7AUSbKx3na7z250FlZqjfEARxx6lb/9kVBmH06LfdEOtvk/TUs6FK\n\t12GUfi0mtjULSUPliCPyMFKrw7yyue5MR/C3dYEMD7mMjWqnLtVg4n8ztBVxmIdPFlyH\n\tANjYOjpSti1BEYyCRKdGHYDVx4a/vvfz9h0Q5UHPPCbF1YvMAL3pwLjF6Cf/F4CHd1tn\n\thW27r28YCdSQoqHsbp9PrYgqPNnRCPKOAg2lHO9tyBgKG+Z1stDasW5PB4dOeHA72xDJ\n\t/uwljysvvtAOFzRXtP1+wR8p9gd2K4fJlwtysAd0wHHXb8Ta6+MkHXN2JaNporhX9B41\n\t9jqw==","X-Gm-Message-State":"AOAM533GZM+XiEzX9nZ2wyinZKQVYieF22C6ZswwEmqzhmB3h/HuNtRK\n\tcUbl716xEByYTbz+1aWUWXA87yUUYS3EbyQC+xbPqordF/1NVw==","X-Google-Smtp-Source":"ABdhPJyEmoNcfx9H2meDCTZ/+SdBtcZYglDJUNxirAf2qbXyCNACUEgzk1tJjcqRqgSkpGmRvcKbe34/MrKwLqOWfZ0=","X-Received":"by 2002:a05:6512:1281:: with SMTP id\n\tu1mr5523394lfs.611.1635338524391; \n\tWed, 27 Oct 2021 05:42:04 -0700 (PDT)","MIME-Version":"1.0","References":"<20211027092803.3671096-1-naush@raspberrypi.com>\n\t<20211027092803.3671096-10-naush@raspberrypi.com>\n\t<163533800433.1184428.1527433292868489588@Monstersaurus>","In-Reply-To":"<163533800433.1184428.1527433292868489588@Monstersaurus>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 27 Oct 2021 13:41:48 +0100","Message-ID":"<CAEmqJPq8Xx7=7OSjuqn_Z7xNde=DxGp+fXj+JOWAbKkZoWuTRA@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000d589cb05cf54ebee\"","Subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","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":20595,"web_url":"https://patchwork.libcamera.org/comment/20595/","msgid":"<YXmaaItGQ1OGfmu2@pendragon.ideasonboard.com>","date":"2021-10-27T18:28:56","subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Wed, Oct 27, 2021 at 10:28:03AM +0100, Naushir Patuck wrote:\n> Sensor flips might change the Bayer order of the requested format. The existing\n> code would set a sensor format along with the appropriate Unicam and ISP input\n> formats, but reset the latter two on start() once the flips had been requested.\n> \n> We can now set the sensor flips just before we set the sensor mode in\n> configure(), thereby not needing the second pair of format sets in start().\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 56 ++++++-------------\n>  1 file changed, 16 insertions(+), 40 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 52521857b61c..eaa2676b891e 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -657,16 +657,28 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\t}\n>  \t}\n>  \n> +\t/*\n> +\t * Configure the H/V flip controls based on the combination of\n> +\t * the sensor and user transform.\n> +\t */\n> +\tif (data->supportsFlips_) {\n> +\t\tconst RPiCameraConfiguration *rpiConfig =\n> +\t\t\tstatic_cast<const RPiCameraConfiguration *>(config);\n> +\t\tControlList controls;\n> +\n> +\t\tcontrols.set(V4L2_CID_HFLIP,\n> +\t\t\t     static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> +\t\tcontrols.set(V4L2_CID_VFLIP,\n> +\t\t\t     static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> +\t\tdata->setSensorControls(controls);\n> +\t}\n> +\n>  \t/* First calculate the best sensor mode we can use based on the user request. */\n>  \tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n>  \tret = data->sensor_->setFormat(&sensorFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\t/*\n> -\t * Unicam image output format. The ISP input format gets set at start,\n> -\t * just in case we have swapped bayer orders due to flips.\n> -\t */\n>  \tV4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, packing);\n>  \tret = data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat);\n>  \tif (ret)\n> @@ -676,10 +688,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\t       << \" - Selected sensor format: \" << sensorFormat.toString()\n>  \t\t       << \" - Selected unicam format: \" << unicamFormat.toString();\n>  \n> -\t/*\n> -\t * This format may be reset on start() if the bayer order has changed\n> -\t * because of flips in the sensor.\n> -\t */\n>  \tret = data->isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n> @@ -902,23 +910,6 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls)\n>  \t\treturn ret;\n>  \t}\n>  \n> -\t/*\n> -\t * IPA configure may have changed the sensor flips - hence the bayer\n> -\t * order. Get the sensor format and set the ISP input now.\n> -\t */\n> -\tV4L2SubdeviceFormat sensorFormat;\n> -\tdata->sensor_->device()->getFormat(0, &sensorFormat);\n> -\n> -\tV4L2DeviceFormat ispFormat;\n> -\tispFormat.fourcc = mbusCodeToBayerFormat(sensorFormat.mbus_code).toV4L2PixelFormat();\n> -\tispFormat.size = sensorFormat.size;\n> -\n> -\tret = data->isp_[Isp::Input].dev()->setFormat(&ispFormat);\n> -\tif (ret) {\n> -\t\tstop(camera);\n> -\t\treturn ret;\n> -\t}\n> -\n>  \t/* Enable SOF event generation. */\n>  \tdata->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n>  \n> @@ -1332,10 +1323,6 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig)\n>  \n>  int RPiCameraData::configureIPA(const CameraConfiguration *config)\n>  {\n> -\t/* We know config must be an RPiCameraConfiguration. */\n> -\tconst RPiCameraConfiguration *rpiConfig =\n> -\t\tstatic_cast<const RPiCameraConfiguration *>(config);\n> -\n>  \tstd::map<unsigned int, IPAStream> streamConfig;\n>  \tstd::map<unsigned int, ControlInfoMap> entityControls;\n>  \tipa::RPi::IPAConfig ipaConfig;\n> @@ -1386,17 +1373,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n>  \t\treturn -EPIPE;\n>  \t}\n>  \n> -\t/*\n> -\t * Configure the H/V flip controls based on the combination of\n> -\t * the sensor and user transform.\n> -\t */\n> -\tif (supportsFlips_) {\n> -\t\tcontrols.set(V4L2_CID_HFLIP,\n> -\t\t\t     static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n> -\t\tcontrols.set(V4L2_CID_VFLIP,\n> -\t\t\t     static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n> -\t}\n> -\n>  \tif (!controls.empty())\n>  \t\tsetSensorControls(controls);\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 197B9BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Oct 2021 18:29:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 66F246487F;\n\tWed, 27 Oct 2021 20:29:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 76A1160123\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Oct 2021 20:29:20 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E286792A;\n\tWed, 27 Oct 2021 20:29:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"V3AE3qgX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1635359360;\n\tbh=VGN1iLXnCJ1KMhsc/CLyT2006n6Q939rAAm4cHmoyA0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=V3AE3qgX9L9v7SECkGmyAWhQAx7AJeGh1S0ozqzRxKxRoeOZyRTrHza57LtojJEts\n\tH75rYgV7kImIAt5DixbQzLDVVoltcVNKSjtMHo5C+rX5N5mnb0/qIv+gMBVG3ZO/bW\n\tmTOBDBE3Y8YYVPB3z92Mbk2Wt8R0D3mV8dH9javI=","Date":"Wed, 27 Oct 2021 21:28:56 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<YXmaaItGQ1OGfmu2@pendragon.ideasonboard.com>","References":"<20211027092803.3671096-1-naush@raspberrypi.com>\n\t<20211027092803.3671096-10-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211027092803.3671096-10-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 9/9] pipeline: raspberrypi: Apply\n\tsensor flips at the start of configure()","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@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]