[{"id":35121,"web_url":"https://patchwork.libcamera.org/comment/35121/","msgid":"<0babcac1bf7f4a93349775738b67996652d778ba.camel@ideasonboard.com>","date":"2025-07-25T10:36:39","subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/people/215/","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"content":"Hi Jacopo,\n\nThanks for the patch!\n\nOn Fri, 2025-07-25 at 12:33 +0200, Jacopo Mondi wrote:\n> Add a function to the V4L2VideoDevice class that allows to\n> bind a video device to a media device context using the\n> VIDIOC_BIND_CONTEXT ioctl.\n> \n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>  src/libcamera/v4l2_videodevice.cpp            | 18\n> ++++++++++++++++++\n>  2 files changed, 20 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h\n> b/include/libcamera/internal/v4l2_videodevice.h\n> index\n> ae6a76cb02090ddadf5ad1331a47fd68585cf586..765574b3e0b52b625e927a50045\n> a61f8c2a0ac6e 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -202,6 +202,8 @@ public:\n>  \n>  \tconst V4L2Capability &caps() const { return caps_; }\n>  \n> +\tint bindContext(unsigned int context);\n> +\n>  \tint getFormat(V4L2DeviceFormat *format);\n>  \tint tryFormat(V4L2DeviceFormat *format);\n>  \tint setFormat(V4L2DeviceFormat *format);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp\n> b/src/libcamera/v4l2_videodevice.cpp\n> index\n> 76bdad40ca8d7a024e4644888737371eff1f09fd..a854f3b10201eaa4f643d0e15fc\n> 04b3c49fbeffe 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -795,6 +795,24 @@ std::string V4L2VideoDevice::logPrefix() const\n>  \t\t(V4L2_TYPE_IS_OUTPUT(bufferType_) ? \":out]\" :\n> \":cap]\");\n>  }\n>  \n> +/**\n> + * \\brief Bind a video device to a media device context\n> + * \\param[in] context The file descriptor that identifies the media\n> device\n> + * context\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::bindContext(unsigned int context)\n> +{\n> +\tstruct v4l2_context c = {};\n> +\tc.context_fd = context;\n> +\n> +\tint ret = ioctl(VIDIOC_BIND_CONTEXT, &c);\n> +\tif (ret)\n> +\t\tLOG(V4L2, Error) << \"Unable to bind context: \" <<\n> strerror(-ret);\n> +\n> +\treturn ret;\n> +}\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n\n> +\n>  /**\n>   * \\brief Retrieve the image format set on the V4L2 video device\n>   * \\param[out] format The image format applied on the video device","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 89974C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 25 Jul 2025 10:36:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1C9F1690B7;\n\tFri, 25 Jul 2025 12:36:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 91994690AC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jul 2025 12:36:42 +0200 (CEST)","from isaac-ThinkPad-T16-Gen-2.lan\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9C44AC73;\n\tFri, 25 Jul 2025 12:36:02 +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=\"BOG9cPgR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753439762;\n\tbh=vXm5LMydFAgSb7lS1F+z6wWe2rjKHwq5bmRit+W2DUk=;\n\th=Subject:From:To:Date:In-Reply-To:References:From;\n\tb=BOG9cPgR1q5ALIJp6/nEWtsuQM62LuiM71D9tvk4SNbdh97rpkgn1Z1ujlaFmGJFv\n\td5wLVqqxUf8AvgnNdyQBT0S9NSva3I/MyJR4/1FQGhGMz8SOsLny8LueYACMnVPhr9\n\tIGk0jXqTTH5F4P1DQz88icBrS3opFmQ67lmsqLJk=","Message-ID":"<0babcac1bf7f4a93349775738b67996652d778ba.camel@ideasonboard.com>","Subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","From":"Isaac Scott <isaac.scott@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 25 Jul 2025 11:36:39 +0100","In-Reply-To":"<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","References":"<20250725-multicontext-v1-0-ea558291e101@ideasonboard.com>\n\t<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.56.2 (by Flathub.org) ","MIME-Version":"1.0","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":35211,"web_url":"https://patchwork.libcamera.org/comment/35211/","msgid":"<175371593078.135557.18019598000813809903@localhost>","date":"2025-07-28T15:18:50","subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nQuoting Jacopo Mondi (2025-07-25 12:33:49)\n> Add a function to the V4L2VideoDevice class that allows to\n> bind a video device to a media device context using the\n> VIDIOC_BIND_CONTEXT ioctl.\n> \n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>  src/libcamera/v4l2_videodevice.cpp            | 18 ++++++++++++++++++\n>  2 files changed, 20 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index ae6a76cb02090ddadf5ad1331a47fd68585cf586..765574b3e0b52b625e927a50045a61f8c2a0ac6e 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -202,6 +202,8 @@ public:\n>  \n>         const V4L2Capability &caps() const { return caps_; }\n>  \n> +       int bindContext(unsigned int context);\n> +\n>         int getFormat(V4L2DeviceFormat *format);\n>         int tryFormat(V4L2DeviceFormat *format);\n>         int setFormat(V4L2DeviceFormat *format);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 76bdad40ca8d7a024e4644888737371eff1f09fd..a854f3b10201eaa4f643d0e15fc04b3c49fbeffe 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -795,6 +795,24 @@ std::string V4L2VideoDevice::logPrefix() const\n>                 (V4L2_TYPE_IS_OUTPUT(bufferType_) ? \":out]\" : \":cap]\");\n>  }\n>  \n> +/**\n> + * \\brief Bind a video device to a media device context\n> + * \\param[in] context The file descriptor that identifies the media device\n> + * context\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::bindContext(unsigned int context)\n> +{\n> +       struct v4l2_context c = {};\n> +       c.context_fd = context;\n> +\n> +       int ret = ioctl(VIDIOC_BIND_CONTEXT, &c);\n> +       if (ret)\n> +               LOG(V4L2, Error) << \"Unable to bind context: \" << strerror(-ret);\n> +\n> +       return ret;\n> +}\n> +\n\nLooks good to me.\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nRegards,\nStefan\n\n>  /**\n>   * \\brief Retrieve the image format set on the V4L2 video device\n>   * \\param[out] format The image format applied on the video device\n> \n> -- \n> 2.49.0\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 B7401BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Jul 2025 15:18:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B391691AD;\n\tMon, 28 Jul 2025 17:18:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E616869158\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Jul 2025 17:18:54 +0200 (CEST)","from ideasonboard.com\n\t(p200300f89f4c845c8e3f30ec5e1afeb9.dip0.t-ipconnect.de\n\t[IPv6:2003:f8:9f4c:845c:8e3f:30ec:5e1a:feb9])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id B13E442B;\n\tMon, 28 Jul 2025 17:18:12 +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=\"YvS4JXSC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753715892;\n\tbh=WpRQtFkPwWIsvfgV6T3mNNzHPQnXvDrulwBLgYP/FAw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=YvS4JXSCtyY1Qu8a4Y6IykmnS08RjQ83uWahT55WNgr/WrIRjWvoevB3tlVAcmf4i\n\t0gjThQEyoSencWvKxwgir90d8cZ4vbW0yst2a0HhqsBIwwPR4PXr3wVGscRyMDSFlC\n\tr/O1wgh1dDnHGnkiSBKQocvEwPGEfZkeS8eujgkA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","References":"<20250725-multicontext-v1-0-ea558291e101@ideasonboard.com>\n\t<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","Subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 28 Jul 2025 17:18:50 +0200","Message-ID":"<175371593078.135557.18019598000813809903@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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":35213,"web_url":"https://patchwork.libcamera.org/comment/35213/","msgid":"<bc36b47a-5bf2-4545-9ba0-cdb8a3dc4107@ideasonboard.com>","date":"2025-07-28T15:26:50","subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 07. 25. 12:33 keltezéssel, Jacopo Mondi írta:\n> Add a function to the V4L2VideoDevice class that allows to\n> bind a video device to a media device context using the\n> VIDIOC_BIND_CONTEXT ioctl.\n> \n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n>   include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>   src/libcamera/v4l2_videodevice.cpp            | 18 ++++++++++++++++++\n>   2 files changed, 20 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index ae6a76cb02090ddadf5ad1331a47fd68585cf586..765574b3e0b52b625e927a50045a61f8c2a0ac6e 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -202,6 +202,8 @@ public:\n>   \n>   \tconst V4L2Capability &caps() const { return caps_; }\n>   \n> +\tint bindContext(unsigned int context);\n> +\n>   \tint getFormat(V4L2DeviceFormat *format);\n>   \tint tryFormat(V4L2DeviceFormat *format);\n>   \tint setFormat(V4L2DeviceFormat *format);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 76bdad40ca8d7a024e4644888737371eff1f09fd..a854f3b10201eaa4f643d0e15fc04b3c49fbeffe 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -795,6 +795,24 @@ std::string V4L2VideoDevice::logPrefix() const\n>   \t\t(V4L2_TYPE_IS_OUTPUT(bufferType_) ? \":out]\" : \":cap]\");\n>   }\n>   \n> +/**\n> + * \\brief Bind a video device to a media device context\n> + * \\param[in] context The file descriptor that identifies the media device\n> + * context\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::bindContext(unsigned int context)\n> +{\n> +\tstruct v4l2_context c = {};\n> +\tc.context_fd = context;\n\nI believe something like\n\n   LOG(V4L2, Debug) << \"Binding context: \" << context;\n\nwould be useful to have here. (And in `V4L2Subevice` as well.)\n\n\nRegards,\nBarnabás Pőcze\n\n> +\n> +\tint ret = ioctl(VIDIOC_BIND_CONTEXT, &c);\n> +\tif (ret)\n> +\t\tLOG(V4L2, Error) << \"Unable to bind context: \" << strerror(-ret);\n> +\n> +\treturn ret;\n> +}\n> +\n>   /**\n>    * \\brief Retrieve the image format set on the V4L2 video device\n>    * \\param[out] format The image format applied on the video device\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 3C0A7BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Jul 2025 15:26:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0313B691AB;\n\tMon, 28 Jul 2025 17:26:55 +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 1E43F69158\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Jul 2025 17:26:54 +0200 (CEST)","from [192.168.33.18] (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E9A2842B;\n\tMon, 28 Jul 2025 17:26:11 +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=\"Dd+75V26\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753716372;\n\tbh=Z3fauE+gjmWo0XVlGkIJaz20dbEhlTcu3t/u1wcxU1U=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=Dd+75V26Mt6cLNU10xdd0sHNbrdx4/pWxoKPN/Bs6XkExo+Luiv0X4hMSv4T8C6HC\n\tBn/Uyh+J2dzppSyNAQlQrlnAkQ4OUU2j6SlvxojziqX6j63c/ZHGuMcWdXsx4mB5IU\n\tqoCv7D5Aj5lIRXpt5iUac34A/2QyusVLvTbkW3aI=","Message-ID":"<bc36b47a-5bf2-4545-9ba0-cdb8a3dc4107@ideasonboard.com>","Date":"Mon, 28 Jul 2025 17:26:50 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250725-multicontext-v1-0-ea558291e101@ideasonboard.com>\n\t<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250725-multicontext-v1-4-ea558291e101@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>"}}]