1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
From 103259e6629a419bc07d6348dd1544213daac45b Mon Sep 17 00:00:00 2001
From: John Cox <jc@kynesim.co.uk>
Date: Thu, 11 Mar 2021 12:51:00 +0000
Subject: [PATCH] media: rpivid: Convert to MPLANE
Use multi-planar interface rather than single plane interface. This
allows dmabufs holding compressed data to be resized.
Signed-off-by: John Cox <jc@kynesim.co.uk>
---
drivers/staging/media/rpivid/rpivid.c | 2 +-
drivers/staging/media/rpivid/rpivid.h | 4 +-
drivers/staging/media/rpivid/rpivid_h265.c | 9 ++-
drivers/staging/media/rpivid/rpivid_video.c | 88 ++++++++++-----------
drivers/staging/media/rpivid/rpivid_video.h | 4 +-
5 files changed, 52 insertions(+), 55 deletions(-)
--- a/drivers/staging/media/rpivid/rpivid.c
+++ b/drivers/staging/media/rpivid/rpivid.c
@@ -283,7 +283,7 @@ static const struct video_device rpivid_
.ioctl_ops = &rpivid_ioctl_ops,
.minor = -1,
.release = video_device_release_empty,
- .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING,
+ .device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING,
};
static const struct v4l2_m2m_ops rpivid_m2m_ops = {
--- a/drivers/staging/media/rpivid/rpivid.h
+++ b/drivers/staging/media/rpivid/rpivid.h
@@ -85,8 +85,8 @@ struct rpivid_ctx {
struct v4l2_fh fh;
struct rpivid_dev *dev;
- struct v4l2_pix_format src_fmt;
- struct v4l2_pix_format dst_fmt;
+ struct v4l2_pix_format_mplane src_fmt;
+ struct v4l2_pix_format_mplane dst_fmt;
int dst_fmt_set;
// fatal_err is set if an error has occurred s.t. decode cannot
// continue (such as running out of CMA)
--- a/drivers/staging/media/rpivid/rpivid_h265.c
+++ b/drivers/staging/media/rpivid/rpivid_h265.c
@@ -1613,7 +1613,7 @@ static void rpivid_h265_setup(struct rpi
de->cmd_copy_gptr = ctx->cmdbufs + 0;
de->frame_c_offset = ctx->dst_fmt.height * 128;
- de->frame_stride = ctx->dst_fmt.bytesperline * 128;
+ de->frame_stride = ctx->dst_fmt.plane_fmt[0].bytesperline * 128;
de->frame_addr =
vb2_dma_contig_plane_dma_addr(&run->dst->vb2_buf, 0);
de->frame_aux = NULL;
@@ -1654,11 +1654,11 @@ static void rpivid_h265_setup(struct rpi
goto fail;
}
if (run->dst->planes[0].length <
- ctx->dst_fmt.sizeimage) {
+ ctx->dst_fmt.plane_fmt[0].sizeimage) {
v4l2_warn(&dev->v4l2_dev,
"Capture plane[0] length (%d) < sizeimage (%d)\n",
run->dst->planes[0].length,
- ctx->dst_fmt.sizeimage);
+ ctx->dst_fmt.plane_fmt[0].sizeimage);
goto fail;
}
@@ -1812,7 +1812,8 @@ static void rpivid_h265_setup(struct rpi
// slices. If this changes we will need idx mapping code.
// Uses sh so here rather than trigger
- vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+ vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
+ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!vq) {
v4l2_err(&dev->v4l2_dev, "VQ gone!\n");
--- a/drivers/staging/media/rpivid/rpivid_video.c
+++ b/drivers/staging/media/rpivid/rpivid_video.c
@@ -42,25 +42,27 @@ static inline unsigned int constrain2x(u
(x > y * 2) ? y : x;
}
-int rpivid_prepare_src_format(struct v4l2_pix_format *pix_fmt)
+int rpivid_prepare_src_format(struct v4l2_pix_format_mplane *pix_fmt)
{
if (pix_fmt->pixelformat != V4L2_PIX_FMT_HEVC_SLICE)
return -EINVAL;
/* Zero bytes per line for encoded source. */
- pix_fmt->bytesperline = 0;
+ pix_fmt->plane_fmt[0].bytesperline = 0;
/* Choose some minimum size since this can't be 0 */
- pix_fmt->sizeimage = max_t(u32, SZ_1K, pix_fmt->sizeimage);
+ pix_fmt->plane_fmt[0].sizeimage = max_t(u32, SZ_1K,
+ pix_fmt->plane_fmt[0].sizeimage);
+ pix_fmt->num_planes = 1;
pix_fmt->field = V4L2_FIELD_NONE;
return 0;
}
-int rpivid_prepare_dst_format(struct v4l2_pix_format *pix_fmt)
+int rpivid_prepare_dst_format(struct v4l2_pix_format_mplane *pix_fmt)
{
unsigned int width = pix_fmt->width;
unsigned int height = pix_fmt->height;
- unsigned int sizeimage = pix_fmt->sizeimage;
- unsigned int bytesperline = pix_fmt->bytesperline;
+ unsigned int sizeimage = pix_fmt->plane_fmt[0].sizeimage;
+ unsigned int bytesperline = pix_fmt->plane_fmt[0].bytesperline;
switch (pix_fmt->pixelformat) {
/* For column formats set bytesperline to column height (stride2) */
@@ -112,8 +114,9 @@ int rpivid_prepare_dst_format(struct v4l
pix_fmt->height = height;
pix_fmt->field = V4L2_FIELD_NONE;
- pix_fmt->bytesperline = bytesperline;
- pix_fmt->sizeimage = sizeimage;
+ pix_fmt->plane_fmt[0].bytesperline = bytesperline;
+ pix_fmt->plane_fmt[0].sizeimage = sizeimage;
+ pix_fmt->num_planes = 1;
return 0;
}
@@ -222,12 +225,12 @@ static u32 pixelformat_from_sps(const st
return pf;
}
-static struct v4l2_pix_format
+static struct v4l2_pix_format_mplane
rpivid_hevc_default_dst_fmt(struct rpivid_ctx * const ctx)
{
const struct v4l2_ctrl_hevc_sps * const sps =
rpivid_find_control_data(ctx, V4L2_CID_MPEG_VIDEO_HEVC_SPS);
- struct v4l2_pix_format pix_fmt = {
+ struct v4l2_pix_format_mplane pix_fmt = {
.width = sps->pic_width_in_luma_samples,
.height = sps->pic_height_in_luma_samples,
.pixelformat = pixelformat_from_sps(sps, 0)
@@ -267,7 +270,7 @@ static int rpivid_g_fmt_vid_cap(struct f
if (!ctx->dst_fmt_set)
ctx->dst_fmt = rpivid_hevc_default_dst_fmt(ctx);
- f->fmt.pix = ctx->dst_fmt;
+ f->fmt.pix_mp = ctx->dst_fmt;
return 0;
}
@@ -276,12 +279,12 @@ static int rpivid_g_fmt_vid_out(struct f
{
struct rpivid_ctx *ctx = rpivid_file2ctx(file);
- f->fmt.pix = ctx->src_fmt;
+ f->fmt.pix_mp = ctx->src_fmt;
return 0;
}
-static inline void copy_color(struct v4l2_pix_format *d,
- const struct v4l2_pix_format *s)
+static inline void copy_color(struct v4l2_pix_format_mplane *d,
+ const struct v4l2_pix_format_mplane *s)
{
d->colorspace = s->colorspace;
d->xfer_func = s->xfer_func;
@@ -298,12 +301,8 @@ static int rpivid_try_fmt_vid_cap(struct
u32 pixelformat;
int i;
- /* Reject format types we don't support */
- if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
- return -EINVAL;
-
for (i = 0; (pixelformat = pixelformat_from_sps(sps, i)) != 0; i++) {
- if (f->fmt.pix.pixelformat == pixelformat)
+ if (f->fmt.pix_mp.pixelformat == pixelformat)
break;
}
@@ -317,23 +316,20 @@ static int rpivid_try_fmt_vid_cap(struct
// We don't have any way of finding out colourspace so believe
// anything we are told - take anything set in src as a default
- if (f->fmt.pix.colorspace == V4L2_COLORSPACE_DEFAULT)
- copy_color(&f->fmt.pix, &ctx->src_fmt);
+ if (f->fmt.pix_mp.colorspace == V4L2_COLORSPACE_DEFAULT)
+ copy_color(&f->fmt.pix_mp, &ctx->src_fmt);
- f->fmt.pix.pixelformat = pixelformat;
- return rpivid_prepare_dst_format(&f->fmt.pix);
+ f->fmt.pix_mp.pixelformat = pixelformat;
+ return rpivid_prepare_dst_format(&f->fmt.pix_mp);
}
static int rpivid_try_fmt_vid_out(struct file *file, void *priv,
struct v4l2_format *f)
{
- if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
- return -EINVAL;
-
- if (rpivid_prepare_src_format(&f->fmt.pix)) {
+ if (rpivid_prepare_src_format(&f->fmt.pix_mp)) {
// Set default src format
- f->fmt.pix.pixelformat = RPIVID_SRC_PIXELFORMAT_DEFAULT;
- rpivid_prepare_src_format(&f->fmt.pix);
+ f->fmt.pix_mp.pixelformat = RPIVID_SRC_PIXELFORMAT_DEFAULT;
+ rpivid_prepare_src_format(&f->fmt.pix_mp);
}
return 0;
}
@@ -353,7 +349,7 @@ static int rpivid_s_fmt_vid_cap(struct f
if (ret)
return ret;
- ctx->dst_fmt = f->fmt.pix;
+ ctx->dst_fmt = f->fmt.pix_mp;
ctx->dst_fmt_set = 1;
return 0;
@@ -374,14 +370,14 @@ static int rpivid_s_fmt_vid_out(struct f
if (ret)
return ret;
- ctx->src_fmt = f->fmt.pix;
+ ctx->src_fmt = f->fmt.pix_mp;
ctx->dst_fmt_set = 0; // Setting src invalidates dst
vq->subsystem_flags |=
VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF;
/* Propagate colorspace information to capture. */
- copy_color(&ctx->dst_fmt, &f->fmt.pix);
+ copy_color(&ctx->dst_fmt, &f->fmt.pix_mp);
return 0;
}
@@ -389,14 +385,14 @@ const struct v4l2_ioctl_ops rpivid_ioctl
.vidioc_querycap = rpivid_querycap,
.vidioc_enum_fmt_vid_cap = rpivid_enum_fmt_vid_cap,
- .vidioc_g_fmt_vid_cap = rpivid_g_fmt_vid_cap,
- .vidioc_try_fmt_vid_cap = rpivid_try_fmt_vid_cap,
- .vidioc_s_fmt_vid_cap = rpivid_s_fmt_vid_cap,
+ .vidioc_g_fmt_vid_cap_mplane = rpivid_g_fmt_vid_cap,
+ .vidioc_try_fmt_vid_cap_mplane = rpivid_try_fmt_vid_cap,
+ .vidioc_s_fmt_vid_cap_mplane = rpivid_s_fmt_vid_cap,
.vidioc_enum_fmt_vid_out = rpivid_enum_fmt_vid_out,
- .vidioc_g_fmt_vid_out = rpivid_g_fmt_vid_out,
- .vidioc_try_fmt_vid_out = rpivid_try_fmt_vid_out,
- .vidioc_s_fmt_vid_out = rpivid_s_fmt_vid_out,
+ .vidioc_g_fmt_vid_out_mplane = rpivid_g_fmt_vid_out,
+ .vidioc_try_fmt_vid_out_mplane = rpivid_try_fmt_vid_out,
+ .vidioc_s_fmt_vid_out_mplane = rpivid_s_fmt_vid_out,
.vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
.vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
@@ -421,7 +417,7 @@ static int rpivid_queue_setup(struct vb2
struct device *alloc_devs[])
{
struct rpivid_ctx *ctx = vb2_get_drv_priv(vq);
- struct v4l2_pix_format *pix_fmt;
+ struct v4l2_pix_format_mplane *pix_fmt;
if (V4L2_TYPE_IS_OUTPUT(vq->type))
pix_fmt = &ctx->src_fmt;
@@ -429,10 +425,10 @@ static int rpivid_queue_setup(struct vb2
pix_fmt = &ctx->dst_fmt;
if (*nplanes) {
- if (sizes[0] < pix_fmt->sizeimage)
+ if (sizes[0] < pix_fmt->plane_fmt[0].sizeimage)
return -EINVAL;
} else {
- sizes[0] = pix_fmt->sizeimage;
+ sizes[0] = pix_fmt->plane_fmt[0].sizeimage;
*nplanes = 1;
}
@@ -471,17 +467,17 @@ static int rpivid_buf_prepare(struct vb2
{
struct vb2_queue *vq = vb->vb2_queue;
struct rpivid_ctx *ctx = vb2_get_drv_priv(vq);
- struct v4l2_pix_format *pix_fmt;
+ struct v4l2_pix_format_mplane *pix_fmt;
if (V4L2_TYPE_IS_OUTPUT(vq->type))
pix_fmt = &ctx->src_fmt;
else
pix_fmt = &ctx->dst_fmt;
- if (vb2_plane_size(vb, 0) < pix_fmt->sizeimage)
+ if (vb2_plane_size(vb, 0) < pix_fmt->plane_fmt[0].sizeimage)
return -EINVAL;
- vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage);
+ vb2_set_plane_payload(vb, 0, pix_fmt->plane_fmt[0].sizeimage);
return 0;
}
@@ -567,7 +563,7 @@ int rpivid_queue_init(void *priv, struct
struct rpivid_ctx *ctx = priv;
int ret;
- src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
src_vq->io_modes = VB2_MMAP | VB2_DMABUF;
src_vq->drv_priv = ctx;
src_vq->buf_struct_size = sizeof(struct rpivid_buffer);
@@ -584,7 +580,7 @@ int rpivid_queue_init(void *priv, struct
if (ret)
return ret;
- dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
dst_vq->drv_priv = ctx;
dst_vq->buf_struct_size = sizeof(struct rpivid_buffer);
--- a/drivers/staging/media/rpivid/rpivid_video.h
+++ b/drivers/staging/media/rpivid/rpivid_video.h
@@ -24,7 +24,7 @@ extern const struct v4l2_ioctl_ops rpivi
int rpivid_queue_init(void *priv, struct vb2_queue *src_vq,
struct vb2_queue *dst_vq);
-int rpivid_prepare_src_format(struct v4l2_pix_format *pix_fmt);
-int rpivid_prepare_dst_format(struct v4l2_pix_format *pix_fmt);
+int rpivid_prepare_src_format(struct v4l2_pix_format_mplane *pix_fmt);
+int rpivid_prepare_dst_format(struct v4l2_pix_format_mplane *pix_fmt);
#endif
|