All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Tomasz Figa <tfiga@chromium.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Nicolas Dufresne <nicolas@ndufresne.ca>,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
	Gustavo Padovan <gustavo.padovan@collabora.com>,
	Boris Brezillon <bbrezillon@collabora.com>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	Sebastian Fricke <sebastian.fricke@collabora.com>,
	Laura Nao <laura.nao@collabora.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dmitry Osipenko <digetx@gmail.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>
Subject: [PATCH v1] media: videobuf2: Allow applications customize data offsets of capture buffers
Date: Tue, 22 Mar 2022 16:23:29 +0300	[thread overview]
Message-ID: <20220322132329.6527-1-dmitry.osipenko@collabora.com> (raw)

Use data offsets provided by applications for multi-planar capture
buffers. This allows V4L to import and use dma-bufs exported by other
subsystems in cases where application wants to customize data offsets
of capture buffers in order to meet hardware alignment requirements of
both dma-buf exporter and importer.

This feature is wanted for providing a better support of media hardware
found on Chromebooks. In particular display and camera ISP hardware of
Rockchip and MediaTek SoCs require special handling by userspace because
display h/w has specific alignment requirements that don't match default
alignments expected by V4L and there is a need to customize the data
offsets in case of multi-planar formats.

Some drivers already have preliminary support for data offsets
customization of capture buffers, like NVIDIA Tegra video decoder driver
for example, and V4L allows applications to provide data offsets for
multi-planar output buffers, let's support such customization for the
capture buffers as well.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 Documentation/userspace-api/media/v4l/buffer.rst | 9 ++++++++-
 drivers/media/common/videobuf2/videobuf2-v4l2.c  | 7 +++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documentation/userspace-api/media/v4l/buffer.rst
index 4638ec64db00..75b1929e2acb 100644
--- a/Documentation/userspace-api/media/v4l/buffer.rst
+++ b/Documentation/userspace-api/media/v4l/buffer.rst
@@ -369,13 +369,20 @@ struct v4l2_plane
       - ``data_offset``
       - Offset in bytes to video data in the plane. Drivers must set this
 	field when ``type`` refers to a capture stream, applications when
-	it refers to an output stream.
+	it refers to an output or capture stream.
 
 	.. note::
 
 	   That data_offset is included  in ``bytesused``. So the
 	   size of the image in the plane is ``bytesused``-``data_offset``
 	   at offset ``data_offset`` from the start of the plane.
+
+	   For capture planes data_offset may be specified by applications
+	   and by drivers. Driver may override application's offset or error
+	   out buffer if offset can't be satisfied by hardware. This allows
+	   applications to customize data offsets of imported dma-bufs.
+	   Handling of application's offsets is driver-dependent, application
+	   must use the resulting buffer offset.
     * - __u32
       - ``reserved[11]``
       - Reserved for future use. Should be zeroed by drivers and
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 6edf4508c636..929107a431cc 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -263,6 +263,13 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b
 						psrc->bytesused : pdst->length;
 				pdst->data_offset = psrc->data_offset;
 			}
+		} else {
+			for (plane = 0; plane < vb->num_planes; ++plane) {
+				struct vb2_plane *pdst = &planes[plane];
+				struct v4l2_plane *psrc = &b->m.planes[plane];
+
+				pdst->data_offset = psrc->data_offset;
+			}
 		}
 	} else {
 		/*
-- 
2.35.1


             reply	other threads:[~2022-03-22 13:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22 13:23 Dmitry Osipenko [this message]
2022-03-23 13:05 ` [PATCH v1] media: videobuf2: Allow applications customize data offsets of capture buffers Nicolas Dufresne
2022-03-23 14:28   ` Dmitry Osipenko
2022-03-23 19:21     ` Nicolas Dufresne
2022-03-24 18:20       ` Dmitry Osipenko
2022-03-25 12:32         ` Nicolas Dufresne
2022-03-25 13:11           ` Dave Stevenson
2022-04-22 22:50             ` Dmitry Osipenko
2022-05-18 10:26           ` Hans Verkuil
2022-05-19 10:22             ` Dmitry Osipenko
2022-06-29 15:37               ` Dmitry Osipenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220322132329.6527-1-dmitry.osipenko@collabora.com \
    --to=dmitry.osipenko@collabora.com \
    --cc=andrzej.p@collabora.com \
    --cc=bbrezillon@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=daniel.almeida@collabora.com \
    --cc=digetx@gmail.com \
    --cc=gustavo.padovan@collabora.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=laura.nao@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=sebastian.fricke@collabora.com \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.