[{"id":23482,"web_url":"https://patchwork.libcamera.org/comment/23482/","msgid":"<YrBhM0xGPUvb0xwO@pendragon.ideasonboard.com>","date":"2022-06-20T11:59:47","subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Eric,\n\nThank you for the patch.\n\nOn Mon, Jun 20, 2022 at 12:52:39PM +0100, Eric Curtin wrote:\n> There is a limitation that requires input and output to be pixel\n> for pixel identical in terms of height and width. Remove this\n> limitation to enable more hardware that doesn't match. Just start\n> drawing from top left 0, 0 corner. Try and pick the mode closest to the\n> stream size.\n> \n> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Eric Curtin <ecurtin@redhat.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Tested-by: Eric Curtin <ecurtin@redhat.com>\n> ---\n> Changes in v5:\n> - Tested Laurents suggested change successfully\n> - Added to commit message about trying to pick closest\n\nI've also sent a v5, on Sunday (retaining your autorship of course). Did\nI forget to CC you ?\n\n> Changes in v4:\n> - Change commit message to say top left\n> - Spaces to tabs\n> \n> Changes in v3:\n> - Much simplified version of the patch where we just attempt to\n>   draw from point 0, 0. Only in the case where we do not find a\n>   matching mode. Can expand to do centralization, scaling, etc.\n>   in further patches if needs be.\n> \n> Changes in v2:\n> - Tested and support drawing from negative pixel range\n>   kernel parameter (video=960x540@60) was useful here\n> ---\n>  src/cam/kms_sink.cpp | 45 +++++++++++++++++++++++++++++++++++---------\n>  1 file changed, 36 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\n> index 7add81a6..7904bca8 100644\n> --- a/src/cam/kms_sink.cpp\n> +++ b/src/cam/kms_sink.cpp\n> @@ -11,6 +11,7 @@\n>  #include <algorithm>\n>  #include <assert.h>\n>  #include <iostream>\n> +#include <limits.h>\n>  #include <memory>\n>  #include <stdint.h>\n>  #include <string.h>\n> @@ -112,6 +113,7 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n>  \n>  \tconst libcamera::StreamConfiguration &cfg = config.at(0);\n>  \n> +\t/* Find the best mode for the stream size. */\n>  \tconst std::vector<DRM::Mode> &modes = connector_->modes();\n>  \tconst auto iter = std::find_if(modes.begin(), modes.end(),\n>  \t\t\t\t       [&](const DRM::Mode &mode) {\n> @@ -120,6 +122,32 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n>  \t\t\t\t       });\n>  \tif (iter == modes.end()) {\n\nI think you could drop this search, as the iteration over the modes\nbelow should be enough. Would you mind testing the v5 I posted ?\n\n>  \t\tstd::cerr << \"No mode matching \" << cfg.size << std::endl;\n> +\n> +\t\tunsigned int cfgArea = cfg.size.width * cfg.size.height;\n> +\t\tunsigned int bestDistance = UINT_MAX;\n> +\n> +\t\tfor (const DRM::Mode &mode : modes) {\n> +\t\t\tunsigned int modeArea = mode.hdisplay * mode.vdisplay;\n> +\t\t\tunsigned int distance = modeArea > cfgArea\n> +\t\t\t\t\t\t\t? modeArea - cfgArea\n> +\t\t\t\t\t\t\t: cfgArea - modeArea;\n> +\n> +\t\t\tif (distance < bestDistance) {\n> +\t\t\t\tmode_ = &mode;\n> +\t\t\t\tbestDistance = distance;\n> +\n> +\t\t\t\t/*\n> +\t\t\t\t * If the sizes match exactly, there will be no better\n> +\t\t\t\t * match.\n> +\t\t\t\t */\n> +\t\t\t\tif (distance == 0)\n> +\t\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\t}\n> +\n> +\tif (!mode_) {\n> +\t\tstd::cerr << \"No modes\\n\";\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> @@ -127,7 +155,6 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> -\tmode_ = &*iter;\n>  \tsize_ = cfg.size;\n>  \tstride_ = cfg.stride;\n>  \n> @@ -199,10 +226,10 @@ int KMSSink::configurePipeline(const libcamera::PixelFormat &format)\n>  \t\treturn ret;\n>  \t}\n>  \n> -\tstd::cout\n> -\t\t<< \"Using KMS plane \" << plane_->id() << \", CRTC \" << crtc_->id()\n> -\t\t<< \", connector \" << connector_->name()\n> -\t\t<< \" (\" << connector_->id() << \")\" << std::endl;\n> +\tstd::cout << \"Using KMS plane \" << plane_->id() << \", CRTC \"\n> +\t\t  << crtc_->id() << \", connector \" << connector_->name() << \" (\"\n> +\t\t  << connector_->id() << \"), mode \" << mode_->hdisplay << \"x\"\n> +\t\t  << mode_->vdisplay << \"@\" << mode_->vrefresh << std::endl;\n>  \n>  \treturn 0;\n>  }\n> @@ -295,12 +322,12 @@ bool KMSSink::processRequest(libcamera::Request *camRequest)\n>  \t\tdrmRequest->addProperty(plane_, \"CRTC_ID\", crtc_->id());\n>  \t\tdrmRequest->addProperty(plane_, \"SRC_X\", 0 << 16);\n>  \t\tdrmRequest->addProperty(plane_, \"SRC_Y\", 0 << 16);\n> -\t\tdrmRequest->addProperty(plane_, \"SRC_W\", mode_->hdisplay << 16);\n> -\t\tdrmRequest->addProperty(plane_, \"SRC_H\", mode_->vdisplay << 16);\n> +\t\tdrmRequest->addProperty(plane_, \"SRC_W\", size_.width << 16);\n> +\t\tdrmRequest->addProperty(plane_, \"SRC_H\", size_.height << 16);\n>  \t\tdrmRequest->addProperty(plane_, \"CRTC_X\", 0);\n>  \t\tdrmRequest->addProperty(plane_, \"CRTC_Y\", 0);\n> -\t\tdrmRequest->addProperty(plane_, \"CRTC_W\", mode_->hdisplay);\n> -\t\tdrmRequest->addProperty(plane_, \"CRTC_H\", mode_->vdisplay);\n> +\t\tdrmRequest->addProperty(plane_, \"CRTC_W\", size_.width);\n> +\t\tdrmRequest->addProperty(plane_, \"CRTC_H\", size_.height);\n>  \n>  \t\tflags |= DRM::AtomicRequest::FlagAllowModeset;\n>  \t}","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 9F856BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jun 2022 12:00:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F0AE665635;\n\tMon, 20 Jun 2022 14:00:03 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE1BA60498\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 14:00:02 +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 3DC1C25B;\n\tMon, 20 Jun 2022 14:00:02 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655726404;\n\tbh=ibtW1Y4ipNSbSCUsYgGrlzyjKAEruMhTtZfpHM7ENM0=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=HOjnLZgLeqkHgp+lBpnPOKl/n5LYtHG959xFQglfBIltP3Krfrctt2bDBCcLN5Ztq\n\t5SleDgCWJLAsjZdEgpBogzhGCgvfS6qIQ6auNe3NEGLR90LRKtOa7LM0koUvY3bILR\n\tvdFnlSPCjCVh02QQnxGYvD5MyzO6l09QvyqY3qAF0dN/OX/BVBDWv1e9n3bctfocHg\n\tpORgVD5yY2524s9AtSMDLmWYqwZVVRmfizb4eUGFFVkJdo7bmzf6UwTTSK08yH21/P\n\t7xGIEppWSeHwn0lrfPv3ra8EhpRAnycdzmC4VDHUf+rgbWBCqAo3YuWJaDjyKZY94a\n\t0XG6Lv4Wdtxng==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1655726402;\n\tbh=ibtW1Y4ipNSbSCUsYgGrlzyjKAEruMhTtZfpHM7ENM0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=F0QsVYYHZzPWQDOsFb0mox/nnQB/Lq5Lw9iL0RJgW9yKQXz5XU5kH/B4YiYVDKYho\n\tkiBn+OzfrwwFdr5qJgo8cxG5H6rYv3wZYefJPOX8zTWsbDq0atJILsdL3tN4boVTSy\n\tabivjbuWPqDk8bxrjZtazYssu7n7Z+DE3hzmrDZQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"F0QsVYYH\"; dkim-atps=neutral","Date":"Mon, 20 Jun 2022 14:59:47 +0300","To":"Eric Curtin <ecurtin@redhat.com>","Message-ID":"<YrBhM0xGPUvb0xwO@pendragon.ideasonboard.com>","References":"<20220620115238.16138-1-ecurtin@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220620115238.16138-1-ecurtin@redhat.com>","Subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":23492,"web_url":"https://patchwork.libcamera.org/comment/23492/","msgid":"<CAOgh=FxP54d_v=uiCoxrVY7fH3MxkXQg5ehpEbkCvGNwrFMbuA@mail.gmail.com>","date":"2022-06-20T12:33:31","subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","submitter":{"id":101,"url":"https://patchwork.libcamera.org/api/people/101/","name":"Eric Curtin","email":"ecurtin@redhat.com"},"content":"On Mon, 20 Jun 2022 at 13:00, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi Eric,\n>\n> Thank you for the patch.\n>\n> On Mon, Jun 20, 2022 at 12:52:39PM +0100, Eric Curtin wrote:\n> > There is a limitation that requires input and output to be pixel\n> > for pixel identical in terms of height and width. Remove this\n> > limitation to enable more hardware that doesn't match. Just start\n> > drawing from top left 0, 0 corner. Try and pick the mode closest to the\n> > stream size.\n> >\n> > Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > Signed-off-by: Eric Curtin <ecurtin@redhat.com>\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > Tested-by: Eric Curtin <ecurtin@redhat.com>\n> > ---\n> > Changes in v5:\n> > - Tested Laurents suggested change successfully\n> > - Added to commit message about trying to pick closest\n>\n> I've also sent a v5, on Sunday (retaining your autorship of course). Did\n> I forget to CC you ?\n\nJust tested that version exactly and it's perfect (and less code),\nfeel free to add:\n\nTested-by: Eric Curtin <ecurtin@redhat.com>\n\nto that one.\n\nSorry, I copy pasted code snippets from there to test, because I\ncouldn't seem to find it on patchwork. Maybe it's about time I\nswitched from using just git-send-email and gmail for email. I should\nprobably set up some client that makes it easier for me to download\npatches w/o patchwork.\n\n\n>\n> > Changes in v4:\n> > - Change commit message to say top left\n> > - Spaces to tabs\n> >\n> > Changes in v3:\n> > - Much simplified version of the patch where we just attempt to\n> >   draw from point 0, 0. Only in the case where we do not find a\n> >   matching mode. Can expand to do centralization, scaling, etc.\n> >   in further patches if needs be.\n> >\n> > Changes in v2:\n> > - Tested and support drawing from negative pixel range\n> >   kernel parameter (video=960x540@60) was useful here\n> > ---\n> >  src/cam/kms_sink.cpp | 45 +++++++++++++++++++++++++++++++++++---------\n> >  1 file changed, 36 insertions(+), 9 deletions(-)\n> >\n> > diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\n> > index 7add81a6..7904bca8 100644\n> > --- a/src/cam/kms_sink.cpp\n> > +++ b/src/cam/kms_sink.cpp\n> > @@ -11,6 +11,7 @@\n> >  #include <algorithm>\n> >  #include <assert.h>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  #include <memory>\n> >  #include <stdint.h>\n> >  #include <string.h>\n> > @@ -112,6 +113,7 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> >\n> >       const libcamera::StreamConfiguration &cfg = config.at(0);\n> >\n> > +     /* Find the best mode for the stream size. */\n> >       const std::vector<DRM::Mode> &modes = connector_->modes();\n> >       const auto iter = std::find_if(modes.begin(), modes.end(),\n> >                                      [&](const DRM::Mode &mode) {\n> > @@ -120,6 +122,32 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> >                                      });\n> >       if (iter == modes.end()) {\n>\n> I think you could drop this search, as the iteration over the modes\n> below should be enough. Would you mind testing the v5 I posted ?\n>\n> >               std::cerr << \"No mode matching \" << cfg.size << std::endl;\n> > +\n> > +             unsigned int cfgArea = cfg.size.width * cfg.size.height;\n> > +             unsigned int bestDistance = UINT_MAX;\n> > +\n> > +             for (const DRM::Mode &mode : modes) {\n> > +                     unsigned int modeArea = mode.hdisplay * mode.vdisplay;\n> > +                     unsigned int distance = modeArea > cfgArea\n> > +                                                     ? modeArea - cfgArea\n> > +                                                     : cfgArea - modeArea;\n> > +\n> > +                     if (distance < bestDistance) {\n> > +                             mode_ = &mode;\n> > +                             bestDistance = distance;\n> > +\n> > +                             /*\n> > +                              * If the sizes match exactly, there will be no better\n> > +                              * match.\n> > +                              */\n> > +                             if (distance == 0)\n> > +                                     break;\n> > +                     }\n> > +             }\n> > +     }\n> > +\n> > +     if (!mode_) {\n> > +             std::cerr << \"No modes\\n\";\n> >               return -EINVAL;\n> >       }\n> >\n> > @@ -127,7 +155,6 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> >       if (ret < 0)\n> >               return ret;\n> >\n> > -     mode_ = &*iter;\n> >       size_ = cfg.size;\n> >       stride_ = cfg.stride;\n> >\n> > @@ -199,10 +226,10 @@ int KMSSink::configurePipeline(const libcamera::PixelFormat &format)\n> >               return ret;\n> >       }\n> >\n> > -     std::cout\n> > -             << \"Using KMS plane \" << plane_->id() << \", CRTC \" << crtc_->id()\n> > -             << \", connector \" << connector_->name()\n> > -             << \" (\" << connector_->id() << \")\" << std::endl;\n> > +     std::cout << \"Using KMS plane \" << plane_->id() << \", CRTC \"\n> > +               << crtc_->id() << \", connector \" << connector_->name() << \" (\"\n> > +               << connector_->id() << \"), mode \" << mode_->hdisplay << \"x\"\n> > +               << mode_->vdisplay << \"@\" << mode_->vrefresh << std::endl;\n> >\n> >       return 0;\n> >  }\n> > @@ -295,12 +322,12 @@ bool KMSSink::processRequest(libcamera::Request *camRequest)\n> >               drmRequest->addProperty(plane_, \"CRTC_ID\", crtc_->id());\n> >               drmRequest->addProperty(plane_, \"SRC_X\", 0 << 16);\n> >               drmRequest->addProperty(plane_, \"SRC_Y\", 0 << 16);\n> > -             drmRequest->addProperty(plane_, \"SRC_W\", mode_->hdisplay << 16);\n> > -             drmRequest->addProperty(plane_, \"SRC_H\", mode_->vdisplay << 16);\n> > +             drmRequest->addProperty(plane_, \"SRC_W\", size_.width << 16);\n> > +             drmRequest->addProperty(plane_, \"SRC_H\", size_.height << 16);\n> >               drmRequest->addProperty(plane_, \"CRTC_X\", 0);\n> >               drmRequest->addProperty(plane_, \"CRTC_Y\", 0);\n> > -             drmRequest->addProperty(plane_, \"CRTC_W\", mode_->hdisplay);\n> > -             drmRequest->addProperty(plane_, \"CRTC_H\", mode_->vdisplay);\n> > +             drmRequest->addProperty(plane_, \"CRTC_W\", size_.width);\n> > +             drmRequest->addProperty(plane_, \"CRTC_H\", size_.height);\n> >\n> >               flags |= DRM::AtomicRequest::FlagAllowModeset;\n> >       }\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\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 F337BBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jun 2022 12:33:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D21165635;\n\tMon, 20 Jun 2022 14:33:51 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0351260498\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 14:33:49 +0200 (CEST)","from mail-qv1-f70.google.com (mail-qv1-f70.google.com\n\t[209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-468-dzbA2g2YMXGiqJZ4_owNxg-1; Mon, 20 Jun 2022 08:33:47 -0400","by mail-qv1-f70.google.com with SMTP id\n\tkd24-20020a056214401800b0046d7fd4a421so11505934qvb.20\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 05:33:47 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655728431;\n\tbh=Z8p7N115hGAmWFEuDXsATx4yGCYnzdvevrxq05PqLCU=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=YPIdf+UThw7cX59UeLB2yGhCq73YQir077WJ9ZLOPGCzuYKBPdQvKDvma8Z/IAyRO\n\tYE0HaynDScT+WZE+qd8rQBNrJh2gzU3dEqliK0u4Ghej8X2QsqFZ1zeuQH/VDG4bGf\n\txGQ4RzKCcpkXI3dHqyjL6nTZ8gWnuoTM1GJfFioj6YUuxtHNohWy2F5O4suZzNnR1p\n\tlnBa84YvdPTX78bVLOKvi7jwW/uu9TW/QyqRkSANbOAIFyrsRJNaxBlVl2spT0W8Pp\n\tsW6MVcCo2kPmplMTHfnrwGePSNqXkQjl4c7P0pgIRWvnHogUyDY2M99d0x7hQp+RJ5\n\tUW8TysTj5czVA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1655728428;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=4VyXBvY0pYxoDF80eFOA2KxnjPDNBI4vJ/n2kXdOYKU=;\n\tb=L0THtlt9Y8+JLzW0RV/1qW637RgptqkBkR4cW6wic8UdyydUKLPAXtKPFCwFdeHXAx/wDN\n\t91QFRUGv1BvT0ocKE5qbepEcUhlcfg2hXLfrqDp/KfSRQiDv1PpSKo/nwXG8Z9wBtUO3Sa\n\tJfAobSIfVhXBXJr/d/dYQAsDbsQYMFs="],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"L0THtlt9\"; \n\tdkim-atps=neutral","relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"],"X-MC-Unique":"dzbA2g2YMXGiqJZ4_owNxg-1","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=4VyXBvY0pYxoDF80eFOA2KxnjPDNBI4vJ/n2kXdOYKU=;\n\tb=vCHJ2xtHeTi9AOft/qTxCzSPviH9O5FNLxofa/IU3kFcwk5wn0yC7Dc1JrVulOGIFH\n\tSkD+po2lD/yLmvLgq1y0LMm7UGKkisOyhJHY1HvDBq2c5QARX1PFJz4wvWCOzGFl1eE6\n\tVA6W2wOzTENalzqEqgCISrcGGjA4vf4NiqJllKlCrxC+PqeReqEuUI7WdwXxhglhPep+\n\tLhLmQsePeebkRrUjhpQKQdtc7/+9yUMc/L+oPxljNjElvTmy1+XHP6oVmECRcH4+GCuC\n\t+vbMnjQowsTYwo+fWRJtZ9Z3v7iuBIYlpNAaRABEGPiu5VlM75g23EZv9a92KPEtMTlB\n\t76rQ==","X-Gm-Message-State":"AJIora97djIAdZMp1yAEh034BNMDBJpTOZJ3IS9r1q6RVqcBb9pQw/IY\n\tteoPDcC6xK3Ryp8wX08RsCQj2nC/qvWcnoWueDvlyQafHqZ0i5QRN4GdUd7+1BPKghWq6dAKoqn\n\t+bKmARAHbwGg5K9Seupk1u/7sSf5bmlk0KRLX8swNHc7DzotK1g==","X-Received":["by 2002:a05:622a:1883:b0:305:1ce4:59d2 with SMTP id\n\tv3-20020a05622a188300b003051ce459d2mr19166149qtc.638.1655728427062; \n\tMon, 20 Jun 2022 05:33:47 -0700 (PDT)","by 2002:a05:622a:1883:b0:305:1ce4:59d2 with SMTP id\n\tv3-20020a05622a188300b003051ce459d2mr19166136qtc.638.1655728426778;\n\tMon, 20 Jun 2022 05:33:46 -0700 (PDT)"],"X-Google-Smtp-Source":"AGRyM1sd6fNQzgfCrwo2gZKpmvyLKXMsHjyy7zRwwcFV2I5IZLj5iyP6jisdPUoYyu6t23BiP7wp+ANxJ00rcZkL/Z8=","MIME-Version":"1.0","References":"<20220620115238.16138-1-ecurtin@redhat.com>\n\t<YrBhM0xGPUvb0xwO@pendragon.ideasonboard.com>","In-Reply-To":"<YrBhM0xGPUvb0xwO@pendragon.ideasonboard.com>","Date":"Mon, 20 Jun 2022 13:33:31 +0100","Message-ID":"<CAOgh=FxP54d_v=uiCoxrVY7fH3MxkXQg5ehpEbkCvGNwrFMbuA@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","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>","From":"Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Eric Curtin <ecurtin@redhat.com>","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":23493,"web_url":"https://patchwork.libcamera.org/comment/23493/","msgid":"<YrBsQMQ3y16P9EuT@pendragon.ideasonboard.com>","date":"2022-06-20T12:46:56","subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Eric,\n\nOn Mon, Jun 20, 2022 at 01:33:31PM +0100, Eric Curtin wrote:\n> On Mon, 20 Jun 2022 at 13:00, Laurent Pinchart wrote:\n> > On Mon, Jun 20, 2022 at 12:52:39PM +0100, Eric Curtin wrote:\n> > > There is a limitation that requires input and output to be pixel\n> > > for pixel identical in terms of height and width. Remove this\n> > > limitation to enable more hardware that doesn't match. Just start\n> > > drawing from top left 0, 0 corner. Try and pick the mode closest to the\n> > > stream size.\n> > >\n> > > Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > Signed-off-by: Eric Curtin <ecurtin@redhat.com>\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > Tested-by: Eric Curtin <ecurtin@redhat.com>\n> > > ---\n> > > Changes in v5:\n> > > - Tested Laurents suggested change successfully\n> > > - Added to commit message about trying to pick closest\n> >\n> > I've also sent a v5, on Sunday (retaining your autorship of course). Did\n> > I forget to CC you ?\n> \n> Just tested that version exactly and it's perfect (and less code),\n> feel free to add:\n> \n> Tested-by: Eric Curtin <ecurtin@redhat.com>\n> \n> to that one.\n\nThank you. I'll push the patch shortly.\n\n> Sorry, I copy pasted code snippets from there to test, because I\n> couldn't seem to find it on patchwork. Maybe it's about time I\n> switched from using just git-send-email and gmail for email. I should\n> probably set up some client that makes it easier for me to download\n> patches w/o patchwork.\n\nAnd we also need to setup a public-inbox instance for libcamera, so that\nyou could use b4 to download patches from the list.\n\n> > > Changes in v4:\n> > > - Change commit message to say top left\n> > > - Spaces to tabs\n> > >\n> > > Changes in v3:\n> > > - Much simplified version of the patch where we just attempt to\n> > >   draw from point 0, 0. Only in the case where we do not find a\n> > >   matching mode. Can expand to do centralization, scaling, etc.\n> > >   in further patches if needs be.\n> > >\n> > > Changes in v2:\n> > > - Tested and support drawing from negative pixel range\n> > >   kernel parameter (video=960x540@60) was useful here\n> > > ---\n> > >  src/cam/kms_sink.cpp | 45 +++++++++++++++++++++++++++++++++++---------\n> > >  1 file changed, 36 insertions(+), 9 deletions(-)\n> > >\n> > > diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\n> > > index 7add81a6..7904bca8 100644\n> > > --- a/src/cam/kms_sink.cpp\n> > > +++ b/src/cam/kms_sink.cpp\n> > > @@ -11,6 +11,7 @@\n> > >  #include <algorithm>\n> > >  #include <assert.h>\n> > >  #include <iostream>\n> > > +#include <limits.h>\n> > >  #include <memory>\n> > >  #include <stdint.h>\n> > >  #include <string.h>\n> > > @@ -112,6 +113,7 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> > >\n> > >       const libcamera::StreamConfiguration &cfg = config.at(0);\n> > >\n> > > +     /* Find the best mode for the stream size. */\n> > >       const std::vector<DRM::Mode> &modes = connector_->modes();\n> > >       const auto iter = std::find_if(modes.begin(), modes.end(),\n> > >                                      [&](const DRM::Mode &mode) {\n> > > @@ -120,6 +122,32 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> > >                                      });\n> > >       if (iter == modes.end()) {\n> >\n> > I think you could drop this search, as the iteration over the modes\n> > below should be enough. Would you mind testing the v5 I posted ?\n> >\n> > >               std::cerr << \"No mode matching \" << cfg.size << std::endl;\n> > > +\n> > > +             unsigned int cfgArea = cfg.size.width * cfg.size.height;\n> > > +             unsigned int bestDistance = UINT_MAX;\n> > > +\n> > > +             for (const DRM::Mode &mode : modes) {\n> > > +                     unsigned int modeArea = mode.hdisplay * mode.vdisplay;\n> > > +                     unsigned int distance = modeArea > cfgArea\n> > > +                                                     ? modeArea - cfgArea\n> > > +                                                     : cfgArea - modeArea;\n> > > +\n> > > +                     if (distance < bestDistance) {\n> > > +                             mode_ = &mode;\n> > > +                             bestDistance = distance;\n> > > +\n> > > +                             /*\n> > > +                              * If the sizes match exactly, there will be no better\n> > > +                              * match.\n> > > +                              */\n> > > +                             if (distance == 0)\n> > > +                                     break;\n> > > +                     }\n> > > +             }\n> > > +     }\n> > > +\n> > > +     if (!mode_) {\n> > > +             std::cerr << \"No modes\\n\";\n> > >               return -EINVAL;\n> > >       }\n> > >\n> > > @@ -127,7 +155,6 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config)\n> > >       if (ret < 0)\n> > >               return ret;\n> > >\n> > > -     mode_ = &*iter;\n> > >       size_ = cfg.size;\n> > >       stride_ = cfg.stride;\n> > >\n> > > @@ -199,10 +226,10 @@ int KMSSink::configurePipeline(const libcamera::PixelFormat &format)\n> > >               return ret;\n> > >       }\n> > >\n> > > -     std::cout\n> > > -             << \"Using KMS plane \" << plane_->id() << \", CRTC \" << crtc_->id()\n> > > -             << \", connector \" << connector_->name()\n> > > -             << \" (\" << connector_->id() << \")\" << std::endl;\n> > > +     std::cout << \"Using KMS plane \" << plane_->id() << \", CRTC \"\n> > > +               << crtc_->id() << \", connector \" << connector_->name() << \" (\"\n> > > +               << connector_->id() << \"), mode \" << mode_->hdisplay << \"x\"\n> > > +               << mode_->vdisplay << \"@\" << mode_->vrefresh << std::endl;\n> > >\n> > >       return 0;\n> > >  }\n> > > @@ -295,12 +322,12 @@ bool KMSSink::processRequest(libcamera::Request *camRequest)\n> > >               drmRequest->addProperty(plane_, \"CRTC_ID\", crtc_->id());\n> > >               drmRequest->addProperty(plane_, \"SRC_X\", 0 << 16);\n> > >               drmRequest->addProperty(plane_, \"SRC_Y\", 0 << 16);\n> > > -             drmRequest->addProperty(plane_, \"SRC_W\", mode_->hdisplay << 16);\n> > > -             drmRequest->addProperty(plane_, \"SRC_H\", mode_->vdisplay << 16);\n> > > +             drmRequest->addProperty(plane_, \"SRC_W\", size_.width << 16);\n> > > +             drmRequest->addProperty(plane_, \"SRC_H\", size_.height << 16);\n> > >               drmRequest->addProperty(plane_, \"CRTC_X\", 0);\n> > >               drmRequest->addProperty(plane_, \"CRTC_Y\", 0);\n> > > -             drmRequest->addProperty(plane_, \"CRTC_W\", mode_->hdisplay);\n> > > -             drmRequest->addProperty(plane_, \"CRTC_H\", mode_->vdisplay);\n> > > +             drmRequest->addProperty(plane_, \"CRTC_W\", size_.width);\n> > > +             drmRequest->addProperty(plane_, \"CRTC_H\", size_.height);\n> > >\n> > >               flags |= DRM::AtomicRequest::FlagAllowModeset;\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 BA15BBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jun 2022 12:47:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 112F165637;\n\tMon, 20 Jun 2022 14:47:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4180A60498\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 14:47:12 +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 BABD125B;\n\tMon, 20 Jun 2022 14:47:11 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655729233;\n\tbh=vhYYHT/7ShcHuU8aU42SUFCIoWrMsMw3QIHF6BJpYKM=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=pLz7q1f7B9cXpbpJQOjq4ZhOYqAESZEt2MA9S7QdcQtPTGJhJBlQNhpU6HCBg3edf\n\tBr3Uj7qmIGxynJFpgleqgzRbGTZNdvWo3lEYOoE8lIs2pBES2HlaXMuhDewcaDIITs\n\tbWntNo7RCpZ2b6gVsbNly8bqxf4WQxd6+FxchW2GnyUHGXfMv1waCejaJNS5z1qkIy\n\tHNLLVSuYcZjiiMZM/8YZu+p6H5yzLq9aqO/leW6kPr/H1GkK0hkfli5CkztLceD7a0\n\tessjLA1rTLoJ2FwgsNXYIr6KoV/1QsFiYwovN0RBKM34twZUazQE+bS0ToNs0upBHr\n\tMqAmBUFqIuaeg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1655729232;\n\tbh=vhYYHT/7ShcHuU8aU42SUFCIoWrMsMw3QIHF6BJpYKM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=vo3BAGx6dqvy99rwRJTBi/1mFvmq21CPwkQY5AhcSrZteJcgyE7mrkcKy8BzJx5jg\n\twERCsajpgUD2Nm7fKCSu8XMLVcGU3lWAZim8ldccr5OTsUK6lbcDzU1vwWEDr/0EUV\n\tL+dmcJez1fCYn7P5Aui/Kw1IIAqKR4IyhTqdkAns="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"vo3BAGx6\"; dkim-atps=neutral","Date":"Mon, 20 Jun 2022 15:46:56 +0300","To":"Eric Curtin <ecurtin@redhat.com>","Message-ID":"<YrBsQMQ3y16P9EuT@pendragon.ideasonboard.com>","References":"<20220620115238.16138-1-ecurtin@redhat.com>\n\t<YrBhM0xGPUvb0xwO@pendragon.ideasonboard.com>\n\t<CAOgh=FxP54d_v=uiCoxrVY7fH3MxkXQg5ehpEbkCvGNwrFMbuA@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<CAOgh=FxP54d_v=uiCoxrVY7fH3MxkXQg5ehpEbkCvGNwrFMbuA@mail.gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v5] cam: kms_sink: Remove limitation\n\tthat camera and display must match","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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>"}}]