b114aefacc454e05e180a915b7e9299ad04a090d
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0494-media-vb2-add-V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF.patch
1 From dfcdc4ed9a514cd5d77dd18c6527f257f8aaf378 Mon Sep 17 00:00:00 2001
2 From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
3 Date: Fri, 11 Oct 2019 06:32:40 -0300
4 Subject: [PATCH] media: vb2: add V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF
5
6 This patch adds support for the V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF
7 flag.
8
9 It also adds a new V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF
10 capability.
11
12 Drivers should set vb2_queue->subsystem_flags to
13 VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF to indicate support
14 for this flag.
15
16 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
17 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
18 ---
19 Documentation/media/uapi/v4l/buffer.rst | 13 +++++++++++++
20 Documentation/media/uapi/v4l/vidioc-reqbufs.rst | 6 ++++++
21 drivers/media/common/videobuf2/videobuf2-v4l2.c | 12 ++++++++++--
22 include/media/videobuf2-core.h | 3 +++
23 include/media/videobuf2-v4l2.h | 5 +++++
24 include/uapi/linux/videodev2.h | 13 ++++++++-----
25 6 files changed, 45 insertions(+), 7 deletions(-)
26
27 --- a/Documentation/media/uapi/v4l/buffer.rst
28 +++ b/Documentation/media/uapi/v4l/buffer.rst
29 @@ -607,6 +607,19 @@ Buffer Flags
30 applications shall use this flag for output buffers if the data in
31 this buffer has not been created by the CPU but by some
32 DMA-capable unit, in which case caches have not been used.
33 + * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`:
34 +
35 + - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF``
36 + - 0x00000200
37 + - Only valid if ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` is
38 + set. It is typically used with stateless decoders where multiple
39 + output buffers each decode to a slice of the decoded frame.
40 + Applications can set this flag when queueing the output buffer
41 + to prevent the driver from dequeueing the capture buffer after
42 + the output buffer has been decoded (i.e. the capture buffer is
43 + 'held'). If the timestamp of this output buffer differs from that
44 + of the previous output buffer, then that indicates the start of a
45 + new frame and the previously held capture buffer is dequeued.
46 * .. _`V4L2-BUF-FLAG-LAST`:
47
48 - ``V4L2_BUF_FLAG_LAST``
49 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst
50 +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst
51 @@ -125,6 +125,7 @@ aborting or finishing any DMA in progres
52 .. _V4L2-BUF-CAP-SUPPORTS-DMABUF:
53 .. _V4L2-BUF-CAP-SUPPORTS-REQUESTS:
54 .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS:
55 +.. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF:
56
57 .. cssclass:: longtable
58
59 @@ -150,6 +151,11 @@ aborting or finishing any DMA in progres
60 - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still
61 mapped or exported via DMABUF. These orphaned buffers will be freed
62 when they are unmapped or when the exported DMABUF fds are closed.
63 + * - ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF``
64 + - 0x00000020
65 + - Only valid for stateless decoders. If set, then userspace can set the
66 + ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the
67 + capture buffer until the OUTPUT timestamp changes.
68
69 Return Value
70 ============
71 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
72 +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
73 @@ -49,8 +49,11 @@ module_param(debug, int, 0644);
74 V4L2_BUF_FLAG_REQUEST_FD | \
75 V4L2_BUF_FLAG_TIMESTAMP_MASK)
76 /* Output buffer flags that should be passed on to the driver */
77 -#define V4L2_BUFFER_OUT_FLAGS (V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | \
78 - V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_TIMECODE)
79 +#define V4L2_BUFFER_OUT_FLAGS (V4L2_BUF_FLAG_PFRAME | \
80 + V4L2_BUF_FLAG_BFRAME | \
81 + V4L2_BUF_FLAG_KEYFRAME | \
82 + V4L2_BUF_FLAG_TIMECODE | \
83 + V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF)
84
85 /*
86 * __verify_planes_array() - verify that the planes array passed in struct
87 @@ -194,6 +197,7 @@ static int vb2_fill_vb2_v4l2_buffer(stru
88 }
89 vbuf->sequence = 0;
90 vbuf->request_fd = -1;
91 + vbuf->is_held = false;
92
93 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
94 switch (b->memory) {
95 @@ -321,6 +325,8 @@ static int vb2_fill_vb2_v4l2_buffer(stru
96 */
97 vbuf->flags &= ~V4L2_BUF_FLAG_TIMECODE;
98 vbuf->field = b->field;
99 + if (!(q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF))
100 + vbuf->flags &= ~V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
101 } else {
102 /* Zero any output buffer flags as this is a capture buffer */
103 vbuf->flags &= ~V4L2_BUFFER_OUT_FLAGS;
104 @@ -654,6 +660,8 @@ static void fill_buf_caps(struct vb2_que
105 *caps |= V4L2_BUF_CAP_SUPPORTS_USERPTR;
106 if (q->io_modes & VB2_DMABUF)
107 *caps |= V4L2_BUF_CAP_SUPPORTS_DMABUF;
108 + if (q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF)
109 + *caps |= V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF;
110 #ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API
111 if (q->supports_requests)
112 *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS;
113 --- a/include/media/videobuf2-core.h
114 +++ b/include/media/videobuf2-core.h
115 @@ -505,6 +505,8 @@ struct vb2_buf_ops {
116 * @buf_ops: callbacks to deliver buffer information.
117 * between user-space and kernel-space.
118 * @drv_priv: driver private data.
119 + * @subsystem_flags: Flags specific to the subsystem (V4L2/DVB/etc.). Not used
120 + * by the vb2 core.
121 * @buf_struct_size: size of the driver-specific buffer structure;
122 * "0" indicates the driver doesn't want to use a custom buffer
123 * structure type. for example, ``sizeof(struct vb2_v4l2_buffer)``
124 @@ -571,6 +573,7 @@ struct vb2_queue {
125 const struct vb2_buf_ops *buf_ops;
126
127 void *drv_priv;
128 + u32 subsystem_flags;
129 unsigned int buf_struct_size;
130 u32 timestamp_flags;
131 gfp_t gfp_flags;
132 --- a/include/media/videobuf2-v4l2.h
133 +++ b/include/media/videobuf2-v4l2.h
134 @@ -33,6 +33,7 @@
135 * @timecode: frame timecode.
136 * @sequence: sequence count of this frame.
137 * @request_fd: the request_fd associated with this buffer
138 + * @is_held: if true, then this capture buffer was held
139 * @planes: plane information (userptr/fd, length, bytesused, data_offset).
140 *
141 * Should contain enough information to be able to cover all the fields
142 @@ -46,9 +47,13 @@ struct vb2_v4l2_buffer {
143 struct v4l2_timecode timecode;
144 __u32 sequence;
145 __s32 request_fd;
146 + bool is_held;
147 struct vb2_plane planes[VB2_MAX_PLANES];
148 };
149
150 +/* VB2 V4L2 flags as set in vb2_queue.subsystem_flags */
151 +#define VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 0)
152 +
153 /*
154 * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer *
155 */
156 --- a/include/uapi/linux/videodev2.h
157 +++ b/include/uapi/linux/videodev2.h
158 @@ -925,11 +925,12 @@ struct v4l2_requestbuffers {
159 };
160
161 /* capabilities for struct v4l2_requestbuffers and v4l2_create_buffers */
162 -#define V4L2_BUF_CAP_SUPPORTS_MMAP (1 << 0)
163 -#define V4L2_BUF_CAP_SUPPORTS_USERPTR (1 << 1)
164 -#define V4L2_BUF_CAP_SUPPORTS_DMABUF (1 << 2)
165 -#define V4L2_BUF_CAP_SUPPORTS_REQUESTS (1 << 3)
166 -#define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4)
167 +#define V4L2_BUF_CAP_SUPPORTS_MMAP (1 << 0)
168 +#define V4L2_BUF_CAP_SUPPORTS_USERPTR (1 << 1)
169 +#define V4L2_BUF_CAP_SUPPORTS_DMABUF (1 << 2)
170 +#define V4L2_BUF_CAP_SUPPORTS_REQUESTS (1 << 3)
171 +#define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4)
172 +#define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5)
173
174 /**
175 * struct v4l2_plane - plane info for multi-planar buffers
176 @@ -1051,6 +1052,8 @@ static inline __u64 v4l2_timeval_to_ns(c
177 #define V4L2_BUF_FLAG_IN_REQUEST 0x00000080
178 /* timecode field is valid */
179 #define V4L2_BUF_FLAG_TIMECODE 0x00000100
180 +/* Don't return the capture buffer until OUTPUT timestamp changes */
181 +#define V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF 0x00000200
182 /* Buffer is prepared for queuing */
183 #define V4L2_BUF_FLAG_PREPARED 0x00000400
184 /* Cache handling flags */