Add MPEG-2 decoding to Rockchip VPU
Subsystems (3)
v6 cover Add MPEG-2 decoding to Rockchip VPU
This series introduces the decoding infrastructure that will be used to add support for other codecs such as VP8, VP9 and H.264.
The driver is exposes two video device nodes, the encoder being /dev/video0, and decoder /dev/video1. Both devices are associated to a single memory-to-memory queue, and same media device /dev/media0.
This work has been possible thanks to Jonas Karlman, who did the initial MPEG-2 decoding work and also got mpv+ffmpeg working using the Request API.
Patchset applies cleanly on top of:
git://linuxtv.org/hverkuil/media_tree.git tags/br-v5.3c
For those wanting to test, please find a branch here:
http://git.infradead.org/users/ezequielg/linux/shortlog/refs/heads/vpu-mpeg2-v6
Future plans
------------
Once this series is merged the plan is to rename the driver to Hantro VPU, and add support to i.MX8, and then add VP8 and H264 decoding support.
v6:
* Change fill_fmt() helpers to accept only user-defined sizeimage, but not bytesperline.
* Add RK3328 support, contributed by Jonas Karlman.
v5:
* Add helper to clamp height/width based on frmsize
* Modify fill_fmt() helpers to keep user-defined sizeimage/bytesperline when they're big enough
* Fixed a bunch of problems reported by Hans (see per-patch changelog for more details)
v4:
* Fix issues in the probe/remove path preventing the driver from being unloaded/reloaded (Jonas)
* Rework the media controller registration code to simplify the error/remove path (Boris)
* Split the MPEG2 patches (one adding the generic code and one patch per platform)
v3:
* Share more code between the encoder/decoder logic (VB2/V4L2 interface implementation)
* Add a patch to support MPEG2 decoding on RK3288 (Jonas)
* Several fixes/improvements all over the place (see changelog in each patch for more details)
v2:
* Fixed some minor issues brought up by v4l2-compliance.
* Fixed bytesused wrongly assigned 0 on the MPEG-2 decoder.
* Addressed comments from Hans and Tomasz on the pixel format helpers.
Boris Brezillon (8):
media: v4l2-common: Fix v4l2_fill_pixfmt[_mp]() prototypes
media: v4l2-common: Add an helper to apply frmsize constraints
media: v4l2-common: Support custom imagesize in fill_pixfmt() rockchip/vpu: Use v4l2_apply_frmsize_constraints() where appropriate rockchip/vpu: Rename rockchip_vpu_common.h into rockchip_vpu_v4l2.h rockchip/vpu: Move encoder logic to a common place rockchip/vpu: Provide a helper to reset both src and dst formats rockchip/vpu: Prepare things to support decoders
Ezequiel Garcia (4):
rockchip/vpu: Open-code media controller register rockchip/vpu: Support the Request API rockchip/vpu: Add decoder boilerplate rockchip/vpu: Add support for non-standard controls
Jonas Karlman (4):
rockchip/vpu: Add infra to support MPEG-2 decoding rockchip/vpu: Add MPEG2 decoding support to RK3399 rockchip/vpu: Add support for MPEG-2 decoding on RK3288 rockchip/vpu: Add support for MPEG-2 decoding on RK3328
drivers/media/v4l2-core/v4l2-common.c | 90 ++-
drivers/staging/media/rockchip/vpu/Kconfig | 1 +
drivers/staging/media/rockchip/vpu/Makefile | 7 +-
.../media/rockchip/vpu/rk3288_vpu_hw.c | 59 +-
.../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c | 2 +-
.../rockchip/vpu/rk3288_vpu_hw_mpeg2_dec.c | 261 +++++++
.../media/rockchip/vpu/rk3288_vpu_regs.h | 1 +
.../media/rockchip/vpu/rk3399_vpu_hw.c | 71 +-
.../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 8 +-
.../rockchip/vpu/rk3399_vpu_hw_mpeg2_dec.c | 267 +++++++
.../staging/media/rockchip/vpu/rockchip_vpu.h | 110 ++-
.../media/rockchip/vpu/rockchip_vpu_drv.c | 466 ++++++++++--
.../media/rockchip/vpu/rockchip_vpu_enc.c | 571 ---------------
.../media/rockchip/vpu/rockchip_vpu_hw.h | 17 +
.../media/rockchip/vpu/rockchip_vpu_mpeg2.c | 61 ++
.../media/rockchip/vpu/rockchip_vpu_v4l2.c | 692 ++++++++++++++++++
...kchip_vpu_common.h => rockchip_vpu_v4l2.h} | 15 +-
include/media/v4l2-common.h | 10 +-
18 files changed, 2026 insertions(+), 683 deletions(-)
create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_mpeg2_dec.c
create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_mpeg2_dec.c
delete mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_mpeg2.c
create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.c
rename drivers/staging/media/rockchip/vpu/{rockchip_vpu_common.h => rockchip_vpu_v4l2.h} (50%)Signature · 1 line
2.20.1
PATCH v6 1/16 media: v4l2-common: Fix v4l2_fill_pixfmt[_mp]() prototypes
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Width/height and 4CC formats are expressed using u32 types everywhere, let's fix the v4l2_fill_pixfmt[_mp]() prototypes to do the same.
---
Changes from v5:
* None
Changes from v4:
* New patch
drivers/media/v4l2-core/v4l2-common.c | 5 +++-- include/media/v4l2-common.h | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +3 -2
@@ -542,7 +542,7 @@ static inline unsigned int v4l2_format_block_height(const struct v4l2_format_inf }int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt, -int pixelformat,int width,int height) +u32 pixelformat,u32 width,u32 height) {const struct v4l2_format_info *info;struct v4l2_plane_pix_format *plane;
@@ -596,7 +596,8 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt_mp); -int v4l2_fill_pixfmt (struct v4l2_pix_format *pixfmt,int pixelformat,int width,int height) +int v4l2_fill_pixfmt (struct v4l2_pix_format *pixfmt,u32 pixelformat, +u32 width,u32 height) {const struct v4l2_format_info *info;int i;
include/media/v4l2-common.h +4 -4
@@ -420,9 +420,9 @@ struct v4l2_format_info {const struct v4l2_format_info *v4l2_format_info (u32 format); -int v4l2_fill_pixfmt (struct v4l2_pix_format *pixfmt,int pixelformat, -int width,int height); -int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt,int pixelformat, -int width,int height); +int v4l2_fill_pixfmt (struct v4l2_pix_format *pixfmt,u32 pixelformat, +u32 width,u32 height); +int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt,u32 pixelformat, +u32 width,u32 height);#endif /* V4L2_COMMON_H_ */
Signature · 1 line
2.20.1
PATCH v6 2/16 media: v4l2-common: Add an helper to apply frmsize constraints
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
The rockchip VPU driver is open-coding this logic which seems pretty generic. Let's provide an helper to apply the min/max and alignment constraints on width/height.
---
Changes from v5:
* None
Changes from v4:
* New patch
drivers/media/v4l2-core/v4l2-common.c | 27 +++++++++++++++++++++++++++ include/media/v4l2-common.h | 2 ++ 2 files changed, 29 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +27 -0
@@ -331,6 +331,16 @@ static unsigned int clamp_align(unsigned int x, unsigned int min,return x; } +static unsigned int clamp_roundup (unsigned int x,unsigned int min, +unsigned int max,unsigned int alignment) +{ + x =clamp (x, min, max); +if (alignment) + x =round_up (x, alignment); + +return x; +} + void v4l_bound_align_image(u32 *w, unsigned int wmin, unsigned int wmax, unsigned int walign, u32 *h, unsigned int hmin, unsigned int hmax,
@@ -541,6 +551,23 @@ static inline unsigned int v4l2_format_block_height(const struct v4l2_format_infreturn info->block_h[plane]; } +void v4l2_apply_frmsize_constraints (u32 *width,u32 *height, +const struct v4l2_frmsize_stepwise *frmsize) +{ +if (!frmsize) +return ; + +/* +* Clamp width/height to meet min/max constraints and round it up to +* macroblock alignment. +*/ + *width =clamp_roundup (*width, frmsize->min_width, frmsize->max_width, + frmsize->step_width); + *height =clamp_roundup (*height, frmsize->min_height, frmsize->max_height, + frmsize->step_height); +} +EXPORT_SYMBOL_GPL (v4l2_apply_frmsize_constraints); +int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt,u32 pixelformat,u32 width,u32 height) {
include/media/v4l2-common.h +2 -0
@@ -420,6 +420,8 @@ struct v4l2_format_info {const struct v4l2_format_info *v4l2_format_info (u32 format); +void v4l2_apply_frmsize_constraints (u32 *width,u32 *height, +const struct v4l2_frmsize_stepwise *frmsize);int v4l2_fill_pixfmt (struct v4l2_pix_format *pixfmt,u32 pixelformat,u32 width,u32 height); int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
Signature · 1 line
2.20.1
PATCH v6 3/16 media: v4l2-common: Support custom imagesize in fill_pixfmt()
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in fill_pixfmt().
---
Changes from v5:
* Overwrite bytesperline with the value calculated in fill_pixfmt()
Changes from v4:
* New patch
drivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +43 -15
@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;
@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } + +/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage); }else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;
@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */ + plane->bytesperline = info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv); + +/* +* The user might have specified a custom sizeimage, +* only override it if it's not big enough. +*/ + plane->sizeimage =max_t (u32, + plane->bytesperline * +DIV_ROUND_UP (aligned_height, vdiv), + plane->sizeimage); } }return 0 ;
@@ -627,6 +647,7 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height) {const struct v4l2_format_info *info; +u32 sizeimage =0 ;int i; info =v4l2_format_info (pixelformat);
@@ -640,8 +661,6 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;
@@ -651,11 +670,20 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - - pixfmt->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } + +/* Custom bytesperline value is not supported yet. */ + pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified its own sizeimage value, only override +* it if it's not big enough. +*/ + pixfmt->sizeimage =max (sizeimage, pixfmt->sizeimage); +return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);
Signature · 1 line
2.20.1
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:
Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);
No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)
or something similar that would be reasonable.
Quoted 4 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0}else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 629
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +2
-4@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */
Supporting custom bytesperline seems too risky of breaking apps. So, I would drop this comment.
Quoted 44 lines
drivers/media/v4l2-core/v4l2-common.c +11
-0+ plane->bytesperline = info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv); + +/* +* The user might have specified a custom sizeimage, +* only override it if it's not big enough. +*/ + plane->sizeimage =max_t (u32, + plane->bytesperline * +DIV_ROUND_UP (aligned_height, vdiv), + plane->sizeimage); }drivers/media/v4l2-core/v4l2-common.c +4
-6}return 0 ;@@ -627,6 +647,7 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height) {const struct v4l2_format_info *info; +u32 sizeimage =0 ;int i; info =v4l2_format_info (pixelformat);@@ -640,8 +661,6 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -651,11 +670,20 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - - pixfmt->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 686
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified its own sizeimage value, only override +* it if it's not big enough. +*/ + pixfmt->sizeimage =max (sizeimage, pixfmt->sizeimage); +
Same comment applies here: We need to sanitize it from too big sizeimages.
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 689
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);
Thanks,
Mauro
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 68 lines · Mauro Carvalho Chehab
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Quoted 5 lines
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's 0x0a8c0000. So perhaps we can use min(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.
Regards,
Hans
Quoted 86 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0}else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 629
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +2
-4@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */ Supporting custom bytesperline seems too risky of breaking apps. So, I would drop this comment.
Quoted 44 lines
drivers/media/v4l2-core/v4l2-common.c +11
-0+ plane->bytesperline = info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv); + +/* +* The user might have specified a custom sizeimage, +* only override it if it's not big enough. +*/ + plane->sizeimage =max_t (u32, + plane->bytesperline * +DIV_ROUND_UP (aligned_height, vdiv), + plane->sizeimage); }drivers/media/v4l2-core/v4l2-common.c +4
-6}return 0 ;@@ -627,6 +647,7 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height) {const struct v4l2_format_info *info; +u32 sizeimage =0 ;int i; info =v4l2_format_info (pixelformat);@@ -640,8 +661,6 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -651,11 +670,20 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - - pixfmt->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 686
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified its own sizeimage value, only override +* it if it's not big enough. +*/ + pixfmt->sizeimage =max (sizeimage, pixfmt->sizeimage); +Same comment applies here: We need to sanitize it from too big sizeimages.
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 689
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);Thanks,
Mauro
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:
Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)
Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.
Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size = 640*480*2 (plus some alignment value if pertinent)
It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
Quoted 92 lines
Regards,
Hans
Quoted 86 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0}else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 629
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +2
-4@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */ Supporting custom bytesperline seems too risky of breaking apps. So, I would drop this comment.
Quoted 44 lines
drivers/media/v4l2-core/v4l2-common.c +11
-0+ plane->bytesperline = info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv); + +/* +* The user might have specified a custom sizeimage, +* only override it if it's not big enough. +*/ + plane->sizeimage =max_t (u32, + plane->bytesperline * +DIV_ROUND_UP (aligned_height, vdiv), + plane->sizeimage); }drivers/media/v4l2-core/v4l2-common.c +4
-6}return 0 ;@@ -627,6 +647,7 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height) {const struct v4l2_format_info *info; +u32 sizeimage =0 ;int i; info =v4l2_format_info (pixelformat);@@ -640,8 +661,6 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -651,11 +670,20 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - - pixfmt->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 686
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified its own sizeimage value, only override +* it if it's not big enough. +*/ + pixfmt->sizeimage =max (sizeimage, pixfmt->sizeimage); +Same comment applies here: We need to sanitize it from too big sizeimages.
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 689
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);Thanks,
Mauro
Thanks,
Mauro
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 90 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
Quoted 8 lines
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want max_sizeimage to be driver specific I can add it as an extra arg to the fill_pixfmt() funcs.
If that works for you, we'll send a new version of this patch alone (unless you want us to send the whole series again).
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Em Wed, 29 May 2019 14:16:33 +0200
Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]> escreveu:
Quoted 98 lines
Quoted 95 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
Quoted 6 lines
Quoted 3 lines
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.
Works for me.
Quoted 2 lines
If that works for you, we'll send a new version of this patch alone (unless you want us to send the whole series again).
If the other patches on this series don't depend on this, I can apply the PR just skipping this one, applying your patch afterwards.
Thanks,
Mauro
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Em Wed, 29 May 2019 09:26:32 -0300
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 108 lines
Em Wed, 29 May 2019 14:16:33 +0200
Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]> escreveu:Quoted 98 lines
Quoted 95 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
Quoted 6 lines
Quoted 3 lines
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.
Quoted 7 lines
Works for me.
Quoted 2 lines
If that works for you, we'll send a new version of this patch alone (unless you want us to send the whole series again).
If the other patches on this series don't depend on this, I can apply the PR just skipping this one, applying your patch afterwards.
Well, I can also apply the PR as-is and apply an extra patch at the end.
Quoted 3 lines
Thanks,
Mauro
Thanks,
Mauro
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
In reply to Mauro Carvalho ChehabQuoted 108 lines · On Wed, 29 May 2019 09:26:32 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 14:16:33 +0200
Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]> escreveu:Quoted 98 lines
Quoted 95 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
Quoted 6 lines
Quoted 3 lines
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.
Quoted 7 lines
Works for me.
Quoted 2 lines
If that works for you, we'll send a new version of this patch alone (unless you want us to send the whole series again).
If the other patches on this series don't depend on this, I can apply the PR just skipping this one, applying your patch afterwards.
Unfortunately they do. I was just asking if we could send a new version of this patch and let you or Hans apply the other ones from this series on top. If that's too complicated, we'll submit a v7 containing all patches. BTW, any concerns on other patches in this series before we send a new version?
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
In reply to Boris BrezillonQuoted 98 lines · Boris Brezillon
Quoted 95 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
Quoted 6 lines
Quoted 3 lines
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.
Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
Regards,
Hans
Quoted 4 lines
If that works for you, we'll send a new version of this patch alone (unless you want us to send the whole series again).
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 103 lines · On Wed, 29 May 2019 14:31:03 +0200 Hans Verkuil…
Quoted 102 lines · Boris Brezillon
Quoted 98 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
Quoted 7 lines
Quoted 2 lines
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
Hehe, IIRC, you were the one asking for this :P (or maybe I misunderstood what you suggested). I don't think we need to preserve user-defined ->sizeimage for uncompressed fmt in the VPU driver, so I'm perfectly fine implementing a version that overrides ->sizeimage unconditionally.
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
In reply to Hans VerkuilQuoted 103 lines · Hans Verkuil
Quoted 102 lines · Boris Brezillon
Quoted 98 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
Quoted 8 lines
Quoted 2 lines
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
I think this is a good idea, which means just picking all patches except this one (and the RK3328 one).
So it would be patches: 1,2 and 4 to 15.
Boris, Hans: are you OK with this?
Thanks,
Ezequiel
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 113 lines · On Wed, 29 May 2019 11:04:35 -0300 Ezequiel Garcia…
Quoted 103 lines · Hans Verkuil
Quoted 102 lines · Boris Brezillon
Quoted 98 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
Quoted 8 lines
Quoted 2 lines
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
Quoted 6 lines
I think this is a good idea, which means just picking all patches except this one (and the RK3328 one).
So it would be patches: 1,2 and 4 to 15.
Boris, Hans: are you OK with this?
I doesn't work => the prototype of the fill_pixfmt() changed.
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 116 lines · On Wed, 29 May 2019 16:06:10 +0200 Boris Brezillon…
Quoted 113 lines · On Wed, 29 May 2019 11:04:35 -0300 Ezequiel Garcia…
Quoted 111 lines · Hans Verkuil
Quoted 98 lines · Boris Brezillon
Quoted 95 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
Quoted 6 lines
Quoted 3 lines
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
Quoted 8 lines
Quoted 6 lines
I think this is a good idea, which means just picking all patches except this one (and the RK3328 one).
So it would be patches: 1,2 and 4 to 15.
Boris, Hans: are you OK with this?
I doesn't work => the prototype of the
fill_pixfmt()changed.
Forget what I said, dropping patch 3 should work just fine.
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Quoted 122 lines · Boris Brezillon
Quoted 119 lines · On Wed, 29 May 2019 16:06:10 +0200 Boris Brezillon…
Quoted 116 lines · On Wed, 29 May 2019 11:04:35 -0300 Ezequiel Garcia…
Quoted 103 lines · Hans Verkuil
Quoted 102 lines · Boris Brezillon
Quoted 98 lines · On Wed, 29 May 2019 08:58:54 -0300 Mauro Carvalho Chehab…
Em Wed, 29 May 2019 13:43:20 +0200
Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/[email protected]> escreveu:Quoted 73 lines · Mauro Carvalho Chehab
Quoted 72 lines
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)Quoted 8 lines
Quoted 1 line
or something similar that would be reasonable.
I've no idea what's sane.
Buffers can be really large. The largest video resolution defined by CTA-861-G is 10240x4320, so at 4 bytes per pixel that's
0x0a8c0000. So perhaps we can usemin(sizeimage, 0x10000000)? Although we should probably use the clamp function instead of min/max.Well, the max is driver-specific.
For example, for a camera with a max resolution of 640x480 with 2 bytes per pixel as the max format can only be
max_size= 640*480*2 (plus some alignment value if pertinent)It sounds to me that the best would be to have a callback function or value filled by the drivers that would support custom sizeimage.
The core could actually calculate during init (by asking the driver to a very big resolution and getting the returned value), but it sounds better to let the drivers to explicitly calculate it.
Quoted 8 lines
Quoted 2 lines
If we want
max_sizeimageto be driver specific I can add it as an extra arg to thefill_pixfmt()funcs.Looking more closely, only compressed formats can accept a user-specified sizeimage value, and this function is only called for uncompressed formats.
So doesn't that mean that this sizeimage override code can be dropped?
I think this is a good idea, which means just picking all patches except this one (and the RK3328 one).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So it would be patches: 1,2 and 4 to 15.
Boris, Hans: are you OK with this?
I doesn't work => the prototype of the
fill_pixfmt()changed.Forget what I said, dropping patch 3 should work just fine.
Yeah, I have reviewed the code and it seems OK. The prototype is not changed, and the driver is not relying on the sizeimage override feature.
Also, tested on my RK3399 Rockpi board, and MPEG-2 decoding works fine.
v4l2-compliance also passes with no failures.
Seems OK to just drop patch 3.
Thanks,
Ezequiel
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
In reply to Mauro Carvalho ChehabHi Mauro,
Quoted 80 lines · Mauro Carvalho Chehab
Em Tue, 28 May 2019 14:02:19 -0300
Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]> escreveu:Quoted 50 lines
From: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)or something similar that would be reasonable.
Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0}else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i));
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 628
Quoted 7 lines
drivers/media/v4l2-core/v4l2-common.c +2
-4plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */ Supporting custom bytesperline seems too risky of breaking apps. So, I would drop this comment.
We will really need this in the long run in many drivers in order to allow import/export of DMABuf. Without such adaptive feature, we have a software limitation that forces bouncing memory. I have already discussed about adding this feature notably in vivid and uvcvideo on IRC and in conference, which both have no restriction the memory alignment, so should allow importing any kind of video layout.
We already have a partial userspace implementation for this in GStreamer and upstream driver submission should come when the IP is considered stable enough.
Why I think it won't break userspace is that the correct way to use these read-only members of V4L2 struct is to set these to 0, which is also documented.
Adding upper bound seems like a good idea though.
Quoted 58 lines
Quoted 45 lines
drivers/media/v4l2-core/v4l2-common.c +15
-6+ plane->bytesperline = info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv); + +/* +* The user might have specified a custom sizeimage, +* only override it if it's not big enough. +*/ + plane->sizeimage =max_t (u32, + plane->bytesperline * +DIV_ROUND_UP (aligned_height, vdiv), + plane->sizeimage); } }return 0 ;@@ -627,6 +647,7 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height) {const struct v4l2_format_info *info; +u32 sizeimage =0 ;int i; info =v4l2_format_info (pixelformat);@@ -640,8 +661,6 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -651,11 +670,20 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - - pixfmt->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 686
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + pixfmt->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified its own sizeimage value, only override +* it if it's not big enough. +*/ + pixfmt->sizeimage =max (sizeimage, pixfmt->sizeimage); +Same comment applies here: We need to sanitize it from too big sizeimages.
Quoted 7 lines
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, · line 689
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);Thanks,
Mauro
_______________________________________________
Linux-rockchip mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v6 03/16] media: v4l2-common: Support custom imagesize in fill_pixfmt()
Em Wed, 29 May 2019 09:54:09 -0400
Nicolas Dufresne <[email protected]> escreveu:
Quoted 101 lines
Hi Mauro,
Quoted 80 lines · Mauro Carvalho Chehab
Em Tue, 28 May 2019 14:02:19 -0300 Ezequiel Garcia <[email protected]> escreveu:
Quoted 50 lines
From: Boris Brezillon <[email protected]>
Users can define custom sizeimage as long as they're big enough to store the amount of pixels required for a specific width/height under a specific format. Avoid overriding those fields in this case.
We could possibly do the same for bytesperline, but it gets tricky when dealing with !MPLANE definitions, so this case is omitted for now and ->bytesperline is always overwritten with the value calculated in
fill_pixfmt().Signed-off-by Boris Brezillon <[email protected]>---
Changes from v5:
* Overwrite bytesperline with the value calculated infill_pixfmt()Changes from v4:
* New patchdrivers/media/v4l2-core/v4l2-common.c | 58 ++++++++++++++++++++------- 1 file changed, 43 insertions(+), 15 deletions(-)drivers/media/v4l2-core/v4l2-common.c +6
-5@@ -585,9 +585,9 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, pixfmt->num_planes = info->mem_planes;if (info->mem_planes ==1 ) { +u32 sizeimage =0 ; + plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =ALIGN (width,v4l2_format_block_width (info,0 )) * info->bpp[0 ]; - plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -598,10 +598,21 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_width =ALIGN (width,v4l2_format_block_width (info, i)); aligned_height =ALIGN (height,v4l2_format_block_height (info, i)); - plane->sizeimage += info->bpp[i] * -DIV_ROUND_UP (aligned_width, hdiv) * -DIV_ROUND_UP (aligned_height, vdiv); + sizeimage += info->bpp[i] * +DIV_ROUND_UP (aligned_width, hdiv) * +DIV_ROUND_UP (aligned_height, vdiv); } +drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 615
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10
-0+/* Custom bytesperline value is not supported yet. */ + plane->bytesperline =ALIGN (width, +v4l2_format_block_width (info,0 )) * + info->bpp[0 ]; + +/* +* The user might have specified a custom sizeimage, only +* override it if it's not big enough. +*/ + plane->sizeimage =max (sizeimage, plane->sizeimage);No upper limit? That doesn't sound a good idea to me, specially since some (broken) app might not be memset the format to zero before filling the ioctl structure.
Perhaps we could do something like:
sizeimage = min (sizeimage, 2 * plane->sizeimage)or something similar that would be reasonable.
Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0}else {for (i =0 ; i < info->comp_planes; i++) {unsigned int hdiv = (i ==0 ) ?1 : info->hdiv;@@ -613,10 +624,19 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, aligned_height =ALIGN (height,v4l2_format_block_height (info, i));Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, · line 628
Quoted 7 lines
drivers/media/v4l2-core/v4l2-common.c +2
-4plane = &pixfmt->plane_fmt[i]; - plane->bytesperline = - info->bpp[i] *DIV_ROUND_UP (aligned_width, hdiv); - plane->sizeimage = - plane->bytesperline *DIV_ROUND_UP (aligned_height, vdiv); + +/* Custom bytesperline value is not supported yet. */ Supporting custom bytesperline seems too risky of breaking apps. So, I would drop this comment.
We will really need this in the long run in many drivers in order to allow import/export of DMABuf. Without such adaptive feature, we have a software limitation that forces bouncing memory. I have already discussed about adding this feature notably in vivid and uvcvideo on IRC and in conference, which both have no restriction the memory alignment, so should allow importing any kind of video layout.
Quoted 3 lines
We already have a partial userspace implementation for this in GStreamer and upstream driver submission should come when the IP is considered stable enough.
I understand the need. I'm not against an implementation for such feature, provided that it won't break anything.
I guess one of the things we miss at V4L2 API is an indication from userspace about what it supports. I mean, just like we have the caps flags where the Kernel reports what it supports, we could have a similar "userspace caps" field.
Quoted 3 lines
Why I think it won't break userspace is that the correct way to use these read-only members of V4L2 struct is to set these to 0, which is also documented.
Yeah, the apps I'm aware of usually call memset() before filling V4L2 structs. On those, adding this behavior would be ok. Yet, I'm not sure if 100% of (open source) apps do that.
Quoted 1 line
Adding upper bound seems like a good idea though.
Agreed.
Quoted 2 lines
Thanks,
Mauro
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v6 4/16 rockchip/vpu: Use v4l2_apply_frmsize_constraints() where appropriate
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
Use the v4l2_apply_frmsize_constraints() helper instead of open-coding it.
---
Changes from v5:
* None
Changes from v4:
* New patch
.../media/rockchip/vpu/rockchip_vpu_enc.c | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-)
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c +14 -30
@@ -197,15 +197,9 @@ vidioc_try_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f) pix_mp->num_planes =1 ; pix_mp->field =V4L2_FIELD_NONE ; - pix_mp->width =clamp (pix_mp->width, - fmt->frmsize.min_width, - fmt->frmsize.max_width); - pix_mp->height =clamp (pix_mp->height, - fmt->frmsize.min_height, - fmt->frmsize.max_height); -/* Round up to macroblocks. */ - pix_mp->width =round_up (pix_mp->width, fmt->frmsize.step_width); - pix_mp->height =round_up (pix_mp->height, fmt->frmsize.step_height); + +v4l2_apply_frmsize_constraints (&pix_mp->width, &pix_mp->height, + &fmt->frmsize);/* * For compressed formats the application can specify
@@ -226,7 +220,6 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)struct rockchip_vpu_ctx *ctx =fh_to_ctx (priv);struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;const struct rockchip_vpu_fmt *fmt; -unsigned int width, height;int i; vpu_debug(4, "%c%c%c%c\n",
@@ -242,18 +235,13 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f) } pix_mp->field =V4L2_FIELD_NONE ; - width =clamp (pix_mp->width, - ctx->vpu_dst_fmt->frmsize.min_width, - ctx->vpu_dst_fmt->frmsize.max_width); - height =clamp (pix_mp->height, - ctx->vpu_dst_fmt->frmsize.min_height, - ctx->vpu_dst_fmt->frmsize.max_height); -/* Round up to macroblocks. */ - width =round_up (width, ctx->vpu_dst_fmt->frmsize.step_width); - height =round_up (height, ctx->vpu_dst_fmt->frmsize.step_height); + +v4l2_apply_frmsize_constraints (&pix_mp->width, &pix_mp->height, + &ctx->vpu_dst_fmt->frmsize);/* Fill remaining fields */ -v4l2_fill_pixfmt_mp (pix_mp, fmt->fourcc, width, height); +v4l2_fill_pixfmt_mp (pix_mp, fmt->fourcc, pix_mp->width, + pix_mp->height);for (i =0 ; i < pix_mp->num_planes; i++) { memset(pix_mp->plane_fmt[i].reserved, 0,
@@ -272,10 +260,8 @@ void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu,memset (fmt,0 ,sizeof (*fmt)); fmt->num_planes =1 ; - fmt->width =clamp (fmt->width, ctx->vpu_dst_fmt->frmsize.min_width, - ctx->vpu_dst_fmt->frmsize.max_width); - fmt->height =clamp (fmt->height, ctx->vpu_dst_fmt->frmsize.min_height, - ctx->vpu_dst_fmt->frmsize.max_height); +v4l2_apply_frmsize_constraints (&fmt->width, &fmt->height, + &ctx->vpu_dst_fmt->frmsize); fmt->pixelformat = ctx->vpu_dst_fmt->fourcc; fmt->field =V4L2_FIELD_NONE ; fmt->colorspace = V4L2_COLORSPACE_JPEG,
@@ -291,23 +277,21 @@ void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu, struct rockchip_vpu_ctx *ctx) {struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt; -unsigned int width, height; ctx->vpu_src_fmt =rockchip_vpu_get_default_fmt (ctx, false);memset (fmt,0 ,sizeof (*fmt)); - width =clamp (fmt->width, ctx->vpu_dst_fmt->frmsize.min_width, - ctx->vpu_dst_fmt->frmsize.max_width); - height =clamp (fmt->height, ctx->vpu_dst_fmt->frmsize.min_height, - ctx->vpu_dst_fmt->frmsize.max_height); +v4l2_apply_frmsize_constraints (&fmt->width, &fmt->height, + &ctx->vpu_src_fmt->frmsize); fmt->field =V4L2_FIELD_NONE ; fmt->colorspace =V4L2_COLORSPACE_JPEG , fmt->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; fmt->quantization =V4L2_QUANTIZATION_DEFAULT ; fmt->xfer_func =V4L2_XFER_FUNC_DEFAULT ; -v4l2_fill_pixfmt_mp (fmt, ctx->vpu_src_fmt->fourcc, width, height); +v4l2_fill_pixfmt_mp (fmt, ctx->vpu_src_fmt->fourcc, fmt->width, + fmt->height); } static int
Signature · 1 line
2.20.1
PATCH v6 5/16 rockchip/vpu: Open-code media controller register
In reply to Ezequiel GarciaIn preparation to support decoders, using a single memory-to-memory device, we need to roll our own media controller entities registration.
To do that, we define a rockchip_vpu_func object that embeds the video_device object plus all the elements that are needed to attach this vdev to the media device.
--
Changes from v3:
* Rework the media controller registration logic (Boris)
* Fix media controller deregistration (Jonas)
Changes from v2:
* Use kvasprintf instead of kmalloc and snprintf.
* Fix missing kfree in error paths.
* Remove unneeded media_remove_intf_links on error paths.
.../staging/media/rockchip/vpu/rockchip_vpu.h | 39 +++- .../media/rockchip/vpu/rockchip_vpu_drv.c | 207 +++++++++++++++--- 2 files changed, 215 insertions(+), 31 deletions(-)
drivers/staging/media/rockchip/vpu/rockchip_vpu.h +37 -2
@@ -71,12 +71,47 @@ enum rockchip_vpu_codec_mode { RK_VPU_MODE_JPEG_ENC, }; +/* +* struct rockchip_vpu_func - rockchip VPU functionality +* +* @id: processing functionality ID (can be +* %MEDIA_ENT_F_PROC_VIDEO_ENCODER or +* %MEDIA_ENT_F_PROC_VIDEO_DECODER) +* @vdev: &struct video_device that exposes the encoder or +* decoder functionality +* @source_pad: &struct media_pad with the source pad. +* @sink: &struct media_entity pointer with the sink entity +* @sink_pad: &struct media_pad with the sink pad. +* @proc: &struct media_entity pointer with the M2M device itself. +* @proc_pads: &struct media_pad with the @proc pads. +* @intf_devnode: &struct media_intf devnode pointer with the interface +* with controls the M2M device. +* +* Contains everything needed to attach the video device to the media device. +*/ +struct rockchip_vpu_func { +unsigned int id; +struct video_device vdev; +struct media_pad source_pad; +struct media_entity sink; +struct media_pad sink_pad; +struct media_entity proc; +struct media_pad proc_pads[2 ]; +struct media_intf_devnode *intf_devnode; +}; + +static inline struct rockchip_vpu_func * +rockchip_vpu_vdev_to_func (struct video_device *vdev) +{ + return container_of(vdev, struct rockchip_vpu_func, vdev); +} +/** * struct rockchip_vpu_dev - driver data * @v4l2_dev: V4L2 device to register video devices for. * @m2m_dev: mem2mem device associated to this device. * @mdev: media device associated to this device. -* @vfd_enc: Video device for encoder. +* @encoder: encoder functionality. * @pdev: Pointer to VPU platform device. * @dev: Pointer to device for convenient logging using * dev_ macros.
@@ -93,7 +128,7 @@ struct rockchip_vpu_dev {struct v4l2_device v4l2_dev;struct v4l2_m2m_dev *m2m_dev;struct media_device mdev; -struct video_device *vfd_enc; +struct rockchip_vpu_func *encoder;struct platform_device *pdev;struct device *dev;struct clk_bulk_data clocks[ROCKCHIP_VPU_MAX_CLOCKS ];
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +178 -29
276 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 6/16 rockchip/vpu: Support the Request API
In reply to Ezequiel GarciaIntroduce support for the Request API. Although the JPEG encoder does not mandate using the Request API, it's perfectly possible to use it, if the application wants to.
--
Changes from v3:
* None
Changes from v2:
* Drop unrelated mdev.bus_info changes.
* Remove the get_ref and get_ctrl helpers as they are not used yet.
.../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 6 ++++++ .../media/rockchip/vpu/rockchip_vpu_drv.c | 7 +++++++ .../media/rockchip/vpu/rockchip_vpu_enc.c | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+)
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c +6 -0
@@ -113,11 +113,15 @@ void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx)struct rockchip_vpu_dev *vpu = ctx->dev;struct vb2_v4l2_buffer *src_buf, *dst_buf;struct rockchip_vpu_jpeg_ctx jpeg_ctx; +struct media_request *src_req;u32 reg; src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx); + src_req = src_buf->vb2_buf.req_obj.req; +v4l2_ctrl_request_setup (src_req, &ctx->ctrl_handler); +memset (&jpeg_ctx,0 ,sizeof (jpeg_ctx)); jpeg_ctx.buffer =vb2_plane_vaddr (&dst_buf->vb2_buf,0 ); jpeg_ctx.width = ctx->dst_fmt.width;
@@ -153,6 +157,8 @@ void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx) | VEPU_REG_ENCODE_FORMAT_JPEG |VEPU_REG_ENCODE_ENABLE ; +v4l2_ctrl_request_complete (src_req, &ctx->ctrl_handler); +/* Kick the watchdog and start encoding */ schedule_delayed_work (&vpu->watchdog_work,msecs_to_jiffies (2000 ));vepu_write (vpu, reg,VEPU_REG_ENCODE_START );
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +7 -0
@@ -162,6 +162,7 @@ enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; src_vq->lock = &ctx->dev->vpu_mutex; src_vq->dev = ctx->dev->v4l2_dev.dev; + src_vq->supports_requests = true; ret =vb2_queue_init (src_vq);if (ret)
@@ -525,6 +526,11 @@ static void rockchip_vpu_remove_enc_func(struct rockchip_vpu_dev *vpu)video_unregister_device (&func->vdev); } +static const struct media_device_ops rockchip_m2m_media_ops = { + .req_validate = vb2_request_validate, + .req_queue = v4l2_m2m_request_queue, +}; +static int rockchip_vpu_probe (struct platform_device *pdev) {const struct of_device_id *match;
@@ -617,6 +623,7 @@ static int rockchip_vpu_probe(struct platform_device *pdev)strscpy (vpu->mdev.bus_info,"platform: " DRIVER_NAME ,sizeof (vpu->mdev.model));media_device_init (&vpu->mdev); + vpu->mdev.ops = &rockchip_m2m_media_ops; vpu->v4l2_dev.mdev = &vpu->mdev; ret =rockchip_vpu_add_enc_func (vpu);
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c +19 -0
@@ -540,14 +540,33 @@ static void rockchip_vpu_stop_streaming(struct vb2_queue *q) vbuf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);if (!vbuf)break ; +v4l2_ctrl_request_complete (vbuf->vb2_buf.req_obj.req, + &ctx->ctrl_handler);v4l2_m2m_buf_done (vbuf,VB2_BUF_STATE_ERROR ); } } +static void rockchip_vpu_buf_request_complete (struct vb2_buffer *vb) +{ +struct rockchip_vpu_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue); + +v4l2_ctrl_request_complete (vb->req_obj.req, &ctx->ctrl_handler); +} + +static int rockchip_vpu_buf_out_validate (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); + + vbuf->field =V4L2_FIELD_NONE ; +return 0 ; +} +const struct vb2_ops rockchip_vpu_enc_queue_ops = { .queue_setup = rockchip_vpu_queue_setup, .buf_prepare = rockchip_vpu_buf_prepare, .buf_queue = rockchip_vpu_buf_queue, + .buf_out_validate = rockchip_vpu_buf_out_validate, + .buf_request_complete = rockchip_vpu_buf_request_complete, .start_streaming = rockchip_vpu_start_streaming, .stop_streaming = rockchip_vpu_stop_streaming, .wait_prepare = vb2_ops_wait_prepare,
Signature · 1 line
2.20.1
PATCH v6 7/16 rockchip/vpu: Rename rockchip_vpu_common.h into rockchip_vpu_v4l2.h
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
We're about to add prototypes for the vb2/v4l2 helpers shared by the encoder/decoder logic in this file, so let's pick a name that reflects that (rockchip_vpu_common.h was a bit to generic).
---
Changes from v3:
* None
Changes from v2:
* New patch
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c | 2 +-
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 2 +-
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c | 2 +-
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c | 2 +-
.../vpu/{rockchip_vpu_common.h => rockchip_vpu_v4l2.h} | 6 +++---
5 files changed, 7 insertions(+), 7 deletions(-)
rename drivers/staging/media/rockchip/vpu/{rockchip_vpu_common.h => rockchip_vpu_v4l2.h} (88%)drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c +1 -1
@@ -9,7 +9,7 @@#include <media/v4l2-mem2mem.h> #include "rockchip_vpu_jpeg.h" #include "rockchip_vpu.h" -#include "rockchip_vpu_common.h" +#include "rockchip_vpu_v4l2.h" #include "rockchip_vpu_hw.h" #include "rk3288_vpu_regs.h"
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c +1 -1
@@ -27,7 +27,7 @@#include <media/v4l2-mem2mem.h> #include "rockchip_vpu_jpeg.h" #include "rockchip_vpu.h" -#include "rockchip_vpu_common.h" +#include "rockchip_vpu_v4l2.h" #include "rockchip_vpu_hw.h" #include "rk3399_vpu_regs.h"
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1 -1
@@ -24,7 +24,7 @@#include <media/videobuf2-core.h> #include <media/videobuf2-vmalloc.h> -#include "rockchip_vpu_common.h" +#include "rockchip_vpu_v4l2.h" #include "rockchip_vpu.h" #include "rockchip_vpu_hw.h"
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c +1 -1
@@ -28,7 +28,7 @@#include "rockchip_vpu.h" #include "rockchip_vpu_hw.h" -#include "rockchip_vpu_common.h" +#include "rockchip_vpu_v4l2.h" static const struct rockchip_vpu_fmt *rockchip_vpu_find_format (struct rockchip_vpu_ctx *ctx,u32 fourcc)
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.h renamed from drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h +3 -3
@@ -13,8 +13,8 @@* Copyright (C) 2011 Samsung Electronics Co., Ltd. */ -#ifndef ROCKCHIP_VPU_COMMON_H_ -#define ROCKCHIP_VPU_COMMON_H_ +#ifndef ROCKCHIP_VPU_V4L2_H_ +#define ROCKCHIP_VPU_V4L2_H_ #include "rockchip_vpu.h"
@@ -26,4 +26,4 @@ void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu,void rockchip_vpu_enc_reset_dst_fmt (struct rockchip_vpu_dev *vpu,struct rockchip_vpu_ctx *ctx); -#endif /* ROCKCHIP_VPU_COMMON_H_ */ +#endif /* ROCKCHIP_VPU_V4L2_H_ */
Signature · 1 line
2.20.1
PATCH v6 8/16 rockchip/vpu: Move encoder logic to a common place
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
The V4L2/VB2 implementation for the encoder and decoder logic are very similar, so let's rename rockchip_vpu_enc.c file into rockchip_vpu_v4l2.c and remove the _enc_ part in objects/functions exposed in rockchip_vpu_v4l2.h. We also rename the enc_queue_init() function (in rockchip_vpu_drv.c) queue_init() since it will be used to initialize both type of queues.
The implementation itself will be patched to support the decoding case when decoder support is added.
---
Changes from v3:
* None
Changes from v2:
* New patch
drivers/staging/media/rockchip/vpu/Makefile | 2 +-
.../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 14 +++++++-------
.../{rockchip_vpu_enc.c => rockchip_vpu_v4l2.c} | 14 +++++++-------
.../staging/media/rockchip/vpu/rockchip_vpu_v4l2.h | 12 ++++++------
4 files changed, 21 insertions(+), 21 deletions(-)
rename drivers/staging/media/rockchip/vpu/{rockchip_vpu_enc.c => rockchip_vpu_v4l2.c} (97%)drivers/staging/media/rockchip/vpu/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_VIDEO_ROCKCHIP_VPU) += rockchip-vpu.o rockchip-vpu-y += \ rockchip_vpu_drv.o \ - rockchip_vpu_enc.o \ + rockchip_vpu_v4l2.o \ rk3288_vpu_hw.o \ rk3288_vpu_hw_jpeg_enc.o \ rk3399_vpu_hw.o \
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +7 -7
@@ -140,7 +140,7 @@ static struct v4l2_m2m_ops vpu_m2m_ops = { };static int -enc_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq) +queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq) {struct rockchip_vpu_ctx *ctx = priv;int ret;
@@ -148,7 +148,7 @@ enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) src_vq->type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; src_vq->io_modes =VB2_MMAP |VB2_DMABUF ; src_vq->drv_priv = ctx; - src_vq->ops = &rockchip_vpu_enc_queue_ops; + src_vq->ops = &rockchip_vpu_queue_ops; src_vq->mem_ops = &vb2_dma_contig_memops;/*
@@ -179,7 +179,7 @@ enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; dst_vq->io_modes =VB2_MMAP |VB2_DMABUF ; dst_vq->drv_priv = ctx; - dst_vq->ops = &rockchip_vpu_enc_queue_ops; + dst_vq->ops = &rockchip_vpu_queue_ops; dst_vq->mem_ops = &vb2_vmalloc_memops; dst_vq->buf_struct_size =sizeof (struct v4l2_m2m_buffer ); dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ;
@@ -260,7 +260,7 @@ static int rockchip_vpu_open(struct file *filp) ctx->dev = vpu;if (func->id ==MEDIA_ENT_F_PROC_VIDEO_ENCODER ) ctx->fh.m2m_ctx =v4l2_m2m_ctx_init (vpu->m2m_dev, ctx, - &enc_queue_init); + queue_init);else ctx->fh.m2m_ctx =ERR_PTR (-ENODEV );if (IS_ERR (ctx->fh.m2m_ctx)) {
@@ -273,8 +273,8 @@ static int rockchip_vpu_open(struct file *filp) filp->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh); -rockchip_vpu_enc_reset_dst_fmt (vpu, ctx); -rockchip_vpu_enc_reset_src_fmt (vpu, ctx); +rockchip_vpu_reset_dst_fmt (vpu, ctx); +rockchip_vpu_reset_src_fmt (vpu, ctx); ret =rockchip_vpu_ctrls_setup (vpu, ctx);if (ret) {
@@ -487,7 +487,7 @@ static int rockchip_vpu_add_enc_func(struct rockchip_vpu_dev *vpu) vfd->v4l2_dev = &vpu->v4l2_dev; vfd->vfl_dir =VFL_DIR_M2M ; vfd->device_caps =V4L2_CAP_STREAMING |V4L2_CAP_VIDEO_M2M_MPLANE ; - vfd->ioctl_ops = &rockchip_vpu_enc_ioctl_ops; + vfd->ioctl_ops = &rockchip_vpu_ioctl_ops;snprintf (vfd->name,sizeof (vfd->name),"%s-enc" , match->compatible); vpu->encoder = func;
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.c renamed from drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c +7 -7
@@ -250,8 +250,8 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)return 0 ; } -void rockchip_vpu_enc_reset_dst_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx) +void rockchip_vpu_reset_dst_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx) {struct v4l2_pix_format_mplane *fmt = &ctx->dst_fmt;
@@ -273,8 +273,8 @@ void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu, fmt->width * fmt->height * ctx->vpu_dst_fmt->max_depth; } -void rockchip_vpu_enc_reset_src_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx) +void rockchip_vpu_reset_src_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx) {struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt;
@@ -373,11 +373,11 @@ vidioc_s_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f)* the raw format again after we return, so we don't need * anything smarter. */ -rockchip_vpu_enc_reset_src_fmt (vpu, ctx); +rockchip_vpu_reset_src_fmt (vpu, ctx);return 0 ; } -const struct v4l2_ioctl_ops rockchip_vpu_enc_ioctl_ops = { +const struct v4l2_ioctl_ops rockchip_vpu_ioctl_ops = { .vidioc_querycap = vidioc_querycap, .vidioc_enum_framesizes = vidioc_enum_framesizes,
@@ -561,7 +561,7 @@ static int rockchip_vpu_buf_out_validate(struct vb2_buffer *vb)return 0 ; } -const struct vb2_ops rockchip_vpu_enc_queue_ops = { +const struct vb2_ops rockchip_vpu_queue_ops = { .queue_setup = rockchip_vpu_queue_setup, .buf_prepare = rockchip_vpu_buf_prepare, .buf_queue = rockchip_vpu_buf_queue,
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.h +6 -6
@@ -18,12 +18,12 @@#include "rockchip_vpu.h" -extern const struct v4l2_ioctl_ops rockchip_vpu_enc_ioctl_ops; -extern const struct vb2_ops rockchip_vpu_enc_queue_ops; +extern const struct v4l2_ioctl_ops rockchip_vpu_ioctl_ops; +extern const struct vb2_ops rockchip_vpu_queue_ops; -void rockchip_vpu_enc_reset_src_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx); -void rockchip_vpu_enc_reset_dst_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx); +void rockchip_vpu_reset_src_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx); +void rockchip_vpu_reset_dst_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx);#endif /* ROCKCHIP_VPU_V4L2_H_ */
Signature · 1 line
2.20.1
PATCH v6 9/16 rockchip/vpu: Provide a helper to reset both src and dst formats
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
When initializing a context, the core wants to reset both src and dst formats. Right now the order doesn't matter, but if we want to have a valid default width/height on the non-coded/raw format side (src in case of encoders, dst in case of decoders), we need to reset those formats in the right order: first the coded-format side, then the other, such that width and height on the raw format side can be taken from the coded format.
Let's provide a helper that will reset both formats and make sure this is done in the right order.
---
Changes from v2:
* None
Changes from v2:
* New patch
.../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 3 +-- .../staging/media/rockchip/vpu/rockchip_vpu_v4l2.c | 14 ++++++++++---- .../staging/media/rockchip/vpu/rockchip_vpu_v4l2.h | 5 +---- 3 files changed, 12 insertions(+), 10 deletions(-)
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1 -2
@@ -273,8 +273,7 @@ static int rockchip_vpu_open(struct file *filp) filp->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh); -rockchip_vpu_reset_dst_fmt (vpu, ctx); -rockchip_vpu_reset_src_fmt (vpu, ctx); +rockchip_vpu_reset_fmts (ctx); ret =rockchip_vpu_ctrls_setup (vpu, ctx);if (ret) {
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.c +10 -4
@@ -250,8 +250,8 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)return 0 ; } -void rockchip_vpu_reset_dst_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx) +static void rockchip_vpu_reset_dst_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx) {struct v4l2_pix_format_mplane *fmt = &ctx->dst_fmt;
@@ -273,8 +273,8 @@ void rockchip_vpu_reset_dst_fmt(struct rockchip_vpu_dev *vpu, fmt->width * fmt->height * ctx->vpu_dst_fmt->max_depth; } -void rockchip_vpu_reset_src_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx) +static void rockchip_vpu_reset_src_fmt (struct rockchip_vpu_dev *vpu, +struct rockchip_vpu_ctx *ctx) {struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt;
@@ -294,6 +294,12 @@ void rockchip_vpu_reset_src_fmt(struct rockchip_vpu_dev *vpu, fmt->height); } +void rockchip_vpu_reset_fmts (struct rockchip_vpu_ctx *ctx) +{ +rockchip_vpu_reset_dst_fmt (ctx->dev, ctx); +rockchip_vpu_reset_src_fmt (ctx->dev, ctx); +} +static int vidioc_s_fmt_out_mplane (struct file *file,void *priv,struct v4l2_format *f) {
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.h +1 -4
@@ -21,9 +21,6 @@extern const struct v4l2_ioctl_ops rockchip_vpu_ioctl_ops;extern const struct vb2_ops rockchip_vpu_queue_ops; -void rockchip_vpu_reset_src_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx); -void rockchip_vpu_reset_dst_fmt (struct rockchip_vpu_dev *vpu, -struct rockchip_vpu_ctx *ctx); +void rockchip_vpu_reset_fmts (struct rockchip_vpu_ctx *ctx);#endif /* ROCKCHIP_VPU_V4L2_H_ */
Signature · 1 line
2.20.1
PATCH v6 10/16 rockchip/vpu: Prepare things to support decoders
In reply to Ezequiel GarciaFrom: Boris Brezillon <boris.brezillon-ZGY8ohtN/[email protected]>
The code in rockchip_vpu_v4l2 was hardcoded for encoder support. Modify it more generic to support the decoder case so that we can re-use the same vb2/v4l2 ops for both devices.
---
Changes from v4:
* Fix s_fmt() implems WRT to format properties propagation
* s/fmt->pix/fmt->pix_mp/ in try_fmt() (Reported by Hans)
Changes from v3:
* None
Changes from v2:
* New patch
.../staging/media/rockchip/vpu/rockchip_vpu.h | 6 + .../media/rockchip/vpu/rockchip_vpu_v4l2.c | 491 +++++++++++------- 2 files changed, 295 insertions(+), 202 deletions(-)
drivers/staging/media/rockchip/vpu/rockchip_vpu.h +6 -0
@@ -262,4 +262,10 @@ static inline u32 vepu_read(struct rockchip_vpu_dev *vpu, u32 reg) return val; } +static inline bool +rockchip_vpu_is_encoder_ctx (const struct rockchip_vpu_ctx *ctx) +{ +return true; +} +#endif /* ROCKCHIP_VPU_H_ */
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.c +289 -202
687 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 11/16 rockchip/vpu: Add decoder boilerplate
In reply to Ezequiel GarciaThis commit adds the needed boilerplate code to support the VPU in decoding operation. Two v4l2 interfaces are exposed, one for encoding and one for decoding, but a single m2m device is shared by them, so jobs are properly serialized.
--
Changes from v4:
* Remove vpu_common.h inclusion
* Set ->requires_requests from s_fmt() instead of fixing it at queue creation time (suggested by Hans)
Changes from v3:
* Update things according to changes done in the patch introducing custom media controller support (Boris)
* Move the rk3399 vdpu irq definition in the commit introducing MPGEG2 support on rk3399
* Fix media controller deregistration code (Jonas)
Changes from v2:
* Use the common vb2/v4l2 implementation
* Use strscpy instead of strlcpy.
* Abstract vidioc v4l2 api implementations into generic code, creating helpers that can be used by the encoder and the decoder.
* Only prevent S_FMT on the coded format queue, if the peer queue has buffers allocated.
* Refactor the code, adding a buf_finish callback to rockchip_vpu_ctx. With this change, is_enc field is not needed.
* Separate OUTPUT and CAPTURE queue ops (vb2_ops), and create common helpers that can be used by both.
* Pass a no kernel mapping attribute on both ends of the decoder.
--- drivers/staging/media/rockchip/vpu/Kconfig | 1 + .../staging/media/rockchip/vpu/rockchip_vpu.h | 42 ++++- .../media/rockchip/vpu/rockchip_vpu_drv.c | 169 ++++++++++++++---- .../media/rockchip/vpu/rockchip_vpu_v4l2.c | 29 ++- 4 files changed, 203 insertions(+), 38 deletions(-)
drivers/staging/media/rockchip/vpu/Kconfig +1 -0
@@ -3,6 +3,7 @@ config VIDEO_ROCKCHIP_VPU tristate "Rockchip VPU driver" depends on ARCH_ROCKCHIP || COMPILE_TEST depends on VIDEO_DEV && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on MEDIA_CONTROLLER_REQUEST_API select VIDEOBUF2_DMA_CONTIG select VIDEOBUF2_VMALLOC select V4L2_MEM2MEM_DEV
drivers/staging/media/rockchip/vpu/rockchip_vpu.h +39 -3
107 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +136 -33
278 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rockchip_vpu_v4l2.c +27 -2
@@ -36,8 +36,13 @@ rockchip_vpu_get_formats(const struct rockchip_vpu_ctx *ctx, {const struct rockchip_vpu_fmt *formats; - formats = ctx->dev->variant->enc_fmts; - *num_fmts = ctx->dev->variant->num_enc_fmts; +if (rockchip_vpu_is_encoder_ctx (ctx)) { + formats = ctx->dev->variant->enc_fmts; + *num_fmts = ctx->dev->variant->num_enc_fmts; + }else { + formats = ctx->dev->variant->dec_fmts; + *num_fmts = ctx->dev->variant->num_dec_fmts; + }return formats; }
@@ -331,6 +336,22 @@ void rockchip_vpu_reset_fmts(struct rockchip_vpu_ctx *ctx)rockchip_vpu_reset_raw_fmt (ctx); } +static void +rockchip_vpu_update_requires_request (struct rockchip_vpu_ctx *ctx, +u32 fourcc) +{ +switch (fourcc) { +case V4L2_PIX_FMT_JPEG : + ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = false; +break ; +case V4L2_PIX_FMT_MPEG2_SLICE : + ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true; +break ; +default : +break ; + } +} +static int vidioc_s_fmt_out_mplane (struct file *file,void *priv,struct v4l2_format *f) {
@@ -387,6 +408,8 @@ vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f) ctx->dst_fmt.xfer_func = pix_mp->xfer_func; ctx->dst_fmt.quantization = pix_mp->quantization; +rockchip_vpu_update_requires_request (ctx, pix_mp->pixelformat); +vpu_debug (0 ,"OUTPUT codec mode: %d\n" , ctx->vpu_src_fmt->codec_mode);vpu_debug (0 ,"fmt - w: %d, h: %d\n" , pix_mp->width, pix_mp->height);
@@ -456,6 +479,8 @@ static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv,vpu_debug (0 ,"fmt - w: %d, h: %d\n" , pix_mp->width, pix_mp->height); +rockchip_vpu_update_requires_request (ctx, pix_mp->pixelformat); +return 0 ; }
Signature · 1 line
2.20.1
PATCH v6 12/16 rockchip/vpu: Add support for non-standard controls
In reply to Ezequiel GarciaRework the way controls are registered by the driver, so it can support non-standard controls, such as those used by stateless codecs.
--
Changes from v4:
* Remove unused var in rockchip_vpu_ctrls_setup()
Changes from v3:
* None
Changes from v2:
* Got rid of unused ctrls related fields.
* Removed unndeeded is_std internal field.
.../media/rockchip/vpu/rk3288_vpu_hw.c | 2 +- .../media/rockchip/vpu/rk3399_vpu_hw.c | 2 +- .../staging/media/rockchip/vpu/rockchip_vpu.h | 17 ++++++- .../media/rockchip/vpu/rockchip_vpu_drv.c | 51 +++++++++++++++---- 4 files changed, 59 insertions(+), 13 deletions(-)
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c +1 -1
@@ -112,7 +112,7 @@ const struct rockchip_vpu_variant rk3288_vpu_variant = { .enc_fmts = rk3288_vpu_enc_fmts, .num_enc_fmts = ARRAY_SIZE(rk3288_vpu_enc_fmts), .codec_ops = rk3288_vpu_codec_ops, - .codec = RK_VPU_CODEC_JPEG, + .codec = RK_VPU_JPEG_ENCODER, .vepu_irq = rk3288_vepu_irq, .init = rk3288_vpu_hw_init, .clk_names = {"aclk", "hclk"},
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +1 -1
@@ -111,7 +111,7 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .enc_offset = 0x0, .enc_fmts = rk3399_vpu_enc_fmts, .num_enc_fmts = ARRAY_SIZE(rk3399_vpu_enc_fmts), - .codec = RK_VPU_CODEC_JPEG, + .codec = RK_VPU_JPEG_ENCODER, .codec_ops = rk3399_vpu_codec_ops, .vepu_irq = rk3399_vepu_irq, .init = rk3399_vpu_hw_init,
drivers/staging/media/rockchip/vpu/rockchip_vpu.h +16 -1
@@ -34,7 +34,10 @@struct rockchip_vpu_ctx ;struct rockchip_vpu_codec_ops ; -#define RK_VPU_CODEC_JPEG BIT(0) +#define RK_VPU_JPEG_ENCODER BIT(0) +#define RK_VPU_ENCODERS 0x0000ffff + +#define RK_VPU_DECODERS 0xffff0000/** * struct rockchip_vpu_variant - information about VPU hardware variant
@@ -79,6 +82,18 @@ enum rockchip_vpu_codec_mode { RK_VPU_MODE_JPEG_ENC, }; +/* +* struct rockchip_vpu_ctrl - helper type to declare supported controls +* @id: V4L2 control ID (V4L2_CID_xxx) +* @codec: codec id this control belong to (RK_VPU_JPEG_ENCODER, etc.) +* @cfg: control configuration +*/ +struct rockchip_vpu_ctrl { +unsigned int id; +unsigned int codec; +struct v4l2_ctrl_config cfg; +}; +/* * struct rockchip_vpu_func - rockchip VPU functionality *
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +41 -10
87 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 13/16 rockchip/vpu: Add infra to support MPEG-2 decoding
In reply to Ezequiel GarciaFrom: Jonas Karlman <[email protected]>
Only adds structs and helpers to allow supporting MPEG-2 decoding on rockchip SoCs. Support for RK3399 and RK3288 will be added in separate commits
--
Changes from v4:
* Define rockchip_vpu_get_ctrl() and rockchip_vpu_get_ref() prototypes in rockchip_vpu.h
Changes from v3:
* Coding style improvements (Jonas)
* Move RK3399 support in a separate commit
Changes from v2:
* Remove uneeded check from rockchip_vpu_get_ctrl.
* Use user negotiated resolution when programming the hardware.
drivers/staging/media/rockchip/vpu/Makefile | 3 +- .../staging/media/rockchip/vpu/rockchip_vpu.h | 12 ++++ .../media/rockchip/vpu/rockchip_vpu_drv.c | 30 +++++++++ .../media/rockchip/vpu/rockchip_vpu_hw.h | 14 +++++ .../media/rockchip/vpu/rockchip_vpu_mpeg2.c | 61 +++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_mpeg2.c
drivers/staging/media/rockchip/vpu/Makefile +2 -1
@@ -8,4 +8,5 @@ rockchip-vpu-y += \ rk3288_vpu_hw_jpeg_enc.o \ rk3399_vpu_hw.o \ rk3399_vpu_hw_jpeg_enc.o \ - rockchip_vpu_jpeg.o + rockchip_vpu_jpeg.o \ + rockchip_vpu_mpeg2.o
drivers/staging/media/rockchip/vpu/rockchip_vpu.h +12 -0
@@ -27,6 +27,10 @@#define ROCKCHIP_VPU_MAX_CLOCKS 4 +#define MPEG2_MB_DIM 16 +#define MPEG2_MB_WIDTH (w) DIV_ROUND_UP(w, MPEG2_MB_DIM) +#define MPEG2_MB_HEIGHT (h) DIV_ROUND_UP(h, MPEG2_MB_DIM) +#define JPEG_MB_DIM 16#define JPEG_MB_WIDTH (w) DIV_ROUND_UP(w, JPEG_MB_DIM)#define JPEG_MB_HEIGHT (h) DIV_ROUND_UP(h, JPEG_MB_DIM)
@@ -37,6 +41,7 @@ struct rockchip_vpu_codec_ops;#define RK_VPU_JPEG_ENCODER BIT(0)#define RK_VPU_ENCODERS 0x0000ffff +#define RK_VPU_MPEG2_DECODER BIT(16)#define RK_VPU_DECODERS 0xffff0000/**
@@ -76,10 +81,12 @@ struct rockchip_vpu_variant {* enum rockchip_vpu_codec_mode - codec operating mode. * @RK_VPU_MODE_NONE: No operating mode. Used for RAW video formats. * @RK_VPU_MODE_JPEG_ENC: JPEG encoder. +* @RK_VPU_MODE_MPEG2_DEC: MPEG-2 decoder. */ enum rockchip_vpu_codec_mode {RK_VPU_MODE_NONE =-1 ,RK_VPU_MODE_JPEG_ENC , +RK_VPU_MODE_MPEG2_DEC , };/*
@@ -190,6 +197,7 @@ struct rockchip_vpu_dev {* calling v4l2_m2m_job_finish. * @codec_ops: Set of operations related to codec mode. * @jpeg_enc: JPEG-encoding context. +* @mpeg2_dec: MPEG-2-decoding context. */ struct rockchip_vpu_ctx {struct rockchip_vpu_dev *dev;
@@ -215,6 +223,7 @@ struct rockchip_vpu_ctx {/* Specific for particular codec modes. */ union {struct rockchip_vpu_jpeg_enc_hw_ctx jpeg_enc; +struct rockchip_vpu_mpeg2_dec_hw_ctx mpeg2_dec; }; };
@@ -319,4 +328,7 @@ static inline u32 vdpu_read(struct rockchip_vpu_dev *vpu, u32 reg)bool rockchip_vpu_is_encoder_ctx (const struct rockchip_vpu_ctx *ctx); +void *rockchip_vpu_get_ctrl (struct rockchip_vpu_ctx *ctx,u32 id); +dma_addr_t rockchip_vpu_get_ref (struct vb2_queue *q,u64 ts); +#endif /* ROCKCHIP_VPU_H_ */
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +30 -0
@@ -35,6 +35,24 @@ module_param_named(debug, rockchip_vpu_debug, int, 0644);MODULE_PARM_DESC (debug,"Debug level - higher value produces more verbose messages" ); +void *rockchip_vpu_get_ctrl (struct rockchip_vpu_ctx *ctx,u32 id) +{ +struct v4l2_ctrl *ctrl; + + ctrl =v4l2_ctrl_find (&ctx->ctrl_handler, id); +return ctrl ? ctrl->p_cur.p :NULL ; +} + +dma_addr_t rockchip_vpu_get_ref (struct vb2_queue *q,u64 ts) +{ +int index; + + index =vb2_find_timestamp (q, ts,0 ); +if (index >=0 ) +return vb2_dma_contig_plane_dma_addr (q->bufs[index],0 ); +return 0 ; +} + static int rockchip_vpu_enc_buf_finish(struct rockchip_vpu_ctx *ctx, struct vb2_buffer *buf,
@@ -255,6 +273,18 @@ static struct rockchip_vpu_ctrl controls[] = { .step = 1, .def = 50, }, + }, { + .id = V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS, + .codec = RK_VPU_MPEG2_DECODER, + .cfg = { + .elem_size = sizeof(struct v4l2_ctrl_mpeg2_slice_params), + }, + }, { + .id = V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION, + .codec = RK_VPU_MPEG2_DECODER, + .cfg = { + .elem_size = sizeof(struct v4l2_ctrl_mpeg2_quantization), + }, }, };
drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +14 -0
@@ -11,6 +11,7 @@#include <linux/interrupt.h> #include <linux/v4l2-controls.h> +#include <media/mpeg2-ctrls.h> #include <media/videobuf2-core.h> struct rockchip_vpu_dev ;
@@ -38,6 +39,14 @@ struct rockchip_vpu_jpeg_enc_hw_ctx {struct rockchip_vpu_aux_buf bounce_buffer; }; +/** +* struct rockchip_vpu_mpeg2_dec_hw_ctx +* @qtable: Quantization table +*/ +struct rockchip_vpu_mpeg2_dec_hw_ctx { +struct rockchip_vpu_aux_buf qtable; +}; +/** * struct rockchip_vpu_codec_ops - codec mode specific operations *
@@ -83,4 +92,9 @@ void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx);int rockchip_vpu_jpeg_enc_init (struct rockchip_vpu_ctx *ctx);void rockchip_vpu_jpeg_enc_exit (struct rockchip_vpu_ctx *ctx); +void rockchip_vpu_mpeg2_dec_copy_qtable (u8 *qtable, +const struct v4l2_ctrl_mpeg2_quantization *ctrl); +int rockchip_vpu_mpeg2_dec_init (struct rockchip_vpu_ctx *ctx); +void rockchip_vpu_mpeg2_dec_exit (struct rockchip_vpu_ctx *ctx); +#endif /* ROCKCHIP_VPU_HW_H_ */
drivers/staging/media/rockchip/vpu/rockchip_vpu_mpeg2.c new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 14/16 rockchip/vpu: Add MPEG2 decoding support to RK3399
In reply to Ezequiel GarciaFrom: Jonas Karlman <[email protected]>
Add the necessary bits to support MPEG2 decoding on RK3399.
---
Changes from v4:
* Stop including rockchip_vpu_common.h
Changes from v3:
* New patch (was part of another patch before)
drivers/staging/media/rockchip/vpu/Makefile | 1 + .../media/rockchip/vpu/rk3399_vpu_hw.c | 59 +++- .../rockchip/vpu/rk3399_vpu_hw_mpeg2_dec.c | 267 ++++++++++++++++++ .../media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 4 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_mpeg2_dec.c
drivers/staging/media/rockchip/vpu/Makefile +1 -0
@@ -8,5 +8,6 @@ rockchip-vpu-y += \ rk3288_vpu_hw_jpeg_enc.o \ rk3399_vpu_hw.o \ rk3399_vpu_hw_jpeg_enc.o \ + rk3399_vpu_hw_mpeg2_dec.o \ rockchip_vpu_jpeg.o \ rockchip_vpu_mpeg2.o
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +58 -1
91 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_mpeg2_dec.c new file +267 -0
267 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1 -0
@@ -92,6 +92,7 @@ void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx);int rockchip_vpu_jpeg_enc_init (struct rockchip_vpu_ctx *ctx);void rockchip_vpu_jpeg_enc_exit (struct rockchip_vpu_ctx *ctx); +void rk3399_vpu_mpeg2_dec_run (struct rockchip_vpu_ctx *ctx);void rockchip_vpu_mpeg2_dec_copy_qtable (u8 *qtable,const struct v4l2_ctrl_mpeg2_quantization *ctrl);int rockchip_vpu_mpeg2_dec_init (struct rockchip_vpu_ctx *ctx);
Signature · 1 line
2.20.1
PATCH v6 15/16 rockchip/vpu: Add support for MPEG-2 decoding on RK3288
In reply to Ezequiel GarciaFrom: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3288.
---
Changes from v4:
* Stop including rockchip_vpu_common.h
Changes from v3:
* Coding style improvements (Jonas)
* Use ALIGN() instead of div+shift (Jonas)
Changes from v2:
* New patch
drivers/staging/media/rockchip/vpu/Makefile | 1 + .../media/rockchip/vpu/rk3288_vpu_hw.c | 59 +++- .../rockchip/vpu/rk3288_vpu_hw_mpeg2_dec.c | 261 ++++++++++++++++++ .../media/rockchip/vpu/rk3288_vpu_regs.h | 1 + .../media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 5 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_mpeg2_dec.c
drivers/staging/media/rockchip/vpu/Makefile +1 -0
@@ -6,6 +6,7 @@ rockchip-vpu-y += \ rockchip_vpu_v4l2.o \ rk3288_vpu_hw.o \ rk3288_vpu_hw_jpeg_enc.o \ + rk3288_vpu_hw_mpeg2_dec.o \ rk3399_vpu_hw.o \ rk3399_vpu_hw_jpeg_enc.o \ rk3399_vpu_hw_mpeg2_dec.o \
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c +58 -1
91 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_mpeg2_dec.c new file +261 -0
261 lines not on this page · raw message
drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h +1 -0
@@ -438,5 +438,6 @@#define VDPU_REG_REF_BUF_CTRL2_REFBU2_THR (x) (((x) & 0xfff) << 19)#define VDPU_REG_REF_BUF_CTRL2_REFBU2_PICID (x) (((x) & 0x1f) << 14)#define VDPU_REG_REF_BUF_CTRL2_APF_THRESHOLD (x) (((x) & 0x3fff) << 0) +#define VDPU_REG_SOFT_RESET 0x194#endif /* RK3288_VPU_REGS_H_ */
drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1 -0
@@ -92,6 +92,7 @@ void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx);int rockchip_vpu_jpeg_enc_init (struct rockchip_vpu_ctx *ctx);void rockchip_vpu_jpeg_enc_exit (struct rockchip_vpu_ctx *ctx); +void rk3288_vpu_mpeg2_dec_run (struct rockchip_vpu_ctx *ctx);void rk3399_vpu_mpeg2_dec_run (struct rockchip_vpu_ctx *ctx);void rockchip_vpu_mpeg2_dec_copy_qtable (u8 *qtable,const struct v4l2_ctrl_mpeg2_quantization *ctrl);
Signature · 1 line
2.20.1
PATCH v6 16/16 rockchip/vpu: Add support for MPEG-2 decoding on RK3328
In reply to Ezequiel GarciaFrom: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3328.
--
Changes from v5:
* New patch.
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c | 12 ++++++++++++ .../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 1 + drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 3 files changed, 14 insertions(+)
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +12 -0
@@ -175,3 +175,15 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .clk_names = {"aclk", "hclk"}, .num_clocks = 2 }; + +const struct rockchip_vpu_variant rk3328_vpu_variant = { + .dec_offset =0x400 , + .dec_fmts = rk3399_vpu_dec_fmts, + .num_dec_fmts =ARRAY_SIZE (rk3399_vpu_dec_fmts), + .codec =RK_VPU_MPEG2_DECODER , + .codec_ops = rk3399_vpu_codec_ops, + .vdpu_irq = rk3399_vdpu_irq, + .init = rk3399_vpu_hw_init, + .clk_names = {"aclk" ,"hclk" }, + .num_clocks =2 +};
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1 -0
@@ -419,6 +419,7 @@ static const struct v4l2_file_operations rockchip_vpu_fops = {static const struct of_device_id of_rockchip_vpu_match[] = { { .compatible ="rockchip,rk3399-vpu" , .data = &rk3399_vpu_variant, }, + { .compatible ="rockchip,rk3328-vpu" , .data = &rk3328_vpu_variant, }, { .compatible ="rockchip,rk3288-vpu" , .data = &rk3288_vpu_variant, }, {/* sentinel */ } };
drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1 -0
@@ -79,6 +79,7 @@ enum rockchip_vpu_enc_fmt { };extern const struct rockchip_vpu_variant rk3399_vpu_variant; +extern const struct rockchip_vpu_variant rk3328_vpu_variant;extern const struct rockchip_vpu_variant rk3288_vpu_variant;void rockchip_vpu_watchdog (struct work_struct *work);
Signature · 1 line
2.20.1
Re: [PATCH v6 16/16] rockchip/vpu: Add support for MPEG-2 decoding on RK3328
Quoted 40 lines · Ezequiel Garcia
From: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3328.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]>--
Changes from v5:
* New patch.drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c | 12 ++++++++++++ .../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 1 + drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 3 files changed, 14 insertions(+)drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +12
-0@@ -175,3 +175,15 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .clk_names = {"aclk", "hclk"}, .num_clocks = 2 }; + +const struct rockchip_vpu_variant rk3328_vpu_variant = { + .dec_offset =0x400 , + .dec_fmts = rk3399_vpu_dec_fmts, + .num_dec_fmts =ARRAY_SIZE (rk3399_vpu_dec_fmts), + .codec =RK_VPU_MPEG2_DECODER , + .codec_ops = rk3399_vpu_codec_ops, + .vdpu_irq = rk3399_vdpu_irq, + .init = rk3399_vpu_hw_init, + .clk_names = {"aclk" ,"hclk" }, + .num_clocks =2 +};drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c static const struct v4l2_file_operations rockchip_vpu_fops = { · line 422
Quoted 4 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1
-0@@ -419,6 +419,7 @@ static const struct v4l2_file_operations rockchip_vpu_fops = {static const struct of_device_id of_rockchip_vpu_match[] = { { .compatible ="rockchip,rk3399-vpu" , .data = &rk3399_vpu_variant, }, + { .compatible ="rockchip,rk3328-vpu" , .data = &rk3328_vpu_variant, },
This new compatible string should be documented in Documentation/devicetree/bindings/media/rockchip-vpu.txt as well.
I'll take patches 1-15 and drop this one. This patch can be merged once the bindings file is updated as well.
Regards,
Hans
Quoted 16 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0{ .compatible = "rockchip,rk3288-vpu", .data = &rk3288_vpu_variant, }, {/* sentinel */ } };drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1
-0@@ -79,6 +79,7 @@ enum rockchip_vpu_enc_fmt { };extern const struct rockchip_vpu_variant rk3399_vpu_variant; +extern const struct rockchip_vpu_variant rk3328_vpu_variant;extern const struct rockchip_vpu_variant rk3288_vpu_variant;void rockchip_vpu_watchdog (struct work_struct *work);
Re: [PATCH v6 16/16] rockchip/vpu: Add support for MPEG-2 decoding on RK3328
Quoted 42 lines · Hans Verkuil
Quoted 41 lines · Ezequiel Garcia
From: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3328.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]>--
Changes from v5:
* New patch.drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c | 12 ++++++++++++ .../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 1 + drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 3 files changed, 14 insertions(+)drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +12
-0@@ -175,3 +175,15 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .clk_names = {"aclk", "hclk"}, .num_clocks = 2 }; + +const struct rockchip_vpu_variant rk3328_vpu_variant = { + .dec_offset =0x400 , + .dec_fmts = rk3399_vpu_dec_fmts, + .num_dec_fmts =ARRAY_SIZE (rk3399_vpu_dec_fmts), + .codec =RK_VPU_MPEG2_DECODER , + .codec_ops = rk3399_vpu_codec_ops, + .vdpu_irq = rk3399_vdpu_irq, + .init = rk3399_vpu_hw_init, + .clk_names = {"aclk" ,"hclk" }, + .num_clocks =2 +};drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0@@ -419,6 +419,7 @@ static const struct v4l2_file_operations rockchip_vpu_fops = {
Quoted 8 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c static const struct v4l2_file_operations rockchip_vpu_fops = { · line 422
Quoted 3 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1
-0static const struct of_device_id of_rockchip_vpu_match[] = { { .compatible ="rockchip,rk3399-vpu" , .data = &rk3399_vpu_variant, }, + { .compatible ="rockchip,rk3328-vpu" , .data = &rk3328_vpu_variant, },This new compatible string should be documented in
Documentation/devicetree/bindings/media/rockchip-vpu.txtas well.I'll take patches 1-15 and drop this one. This patch can be merged once the bindings file is updated as well.
Looks like the bindings patch did not get picked for v6 :-)
I am a bit unclear on how to handle patch submission that covers multiple subtrees. Should I send a single series including three patches: bindings update, this patch and device tree update? Or is a series with only bindings update and this patch preferred?
Regards,
Jonas
Quoted 21 lines
Regards,
Hans
Quoted 16 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0{ .compatible = "rockchip,rk3288-vpu", .data = &rk3288_vpu_variant, }, {/* sentinel */ } };drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1
-0@@ -79,6 +79,7 @@ enum rockchip_vpu_enc_fmt { };extern const struct rockchip_vpu_variant rk3399_vpu_variant; +extern const struct rockchip_vpu_variant rk3328_vpu_variant;extern const struct rockchip_vpu_variant rk3288_vpu_variant;void rockchip_vpu_watchdog (struct work_struct *work);
Re: [PATCH v6 16/16] rockchip/vpu: Add support for MPEG-2 decoding on RK3328
Quoted 49 lines · Jonas Karlman
Quoted 48 lines · Hans Verkuil
Quoted 40 lines · Ezequiel Garcia
From: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3328.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]>--
Changes from v5:
* New patch.drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c | 12 ++++++++++++ .../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 1 + drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 3 files changed, 14 insertions(+)drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +12
-0@@ -175,3 +175,15 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .clk_names = {"aclk", "hclk"}, .num_clocks = 2 }; + +const struct rockchip_vpu_variant rk3328_vpu_variant = { + .dec_offset =0x400 , + .dec_fmts = rk3399_vpu_dec_fmts, + .num_dec_fmts =ARRAY_SIZE (rk3399_vpu_dec_fmts), + .codec =RK_VPU_MPEG2_DECODER , + .codec_ops = rk3399_vpu_codec_ops, + .vdpu_irq = rk3399_vdpu_irq, + .init = rk3399_vpu_hw_init, + .clk_names = {"aclk" ,"hclk" }, + .num_clocks =2 +};drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c static const struct v4l2_file_operations rockchip_vpu_fops = { · line 422
Quoted 4 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1
-0@@ -419,6 +419,7 @@ static const struct v4l2_file_operations rockchip_vpu_fops = {static const struct of_device_id of_rockchip_vpu_match[] = { { .compatible ="rockchip,rk3399-vpu" , .data = &rk3399_vpu_variant, }, + { .compatible ="rockchip,rk3328-vpu" , .data = &rk3328_vpu_variant, },This new compatible string should be documented in
Documentation/devicetree/bindings/media/rockchip-vpu.txtas well.
Quoted 8 lines
Quoted 2 lines
I'll take patches 1-15 and drop this one. This patch can be merged once the bindings file is updated as well.
Looks like the bindings patch did not get picked for v6 :-)
I am a bit unclear on how to handle patch submission that covers multiple subtrees. Should I send a single series including three patches: bindings update, this patch and device tree update? Or is a series with only bindings update and this patch preferred?
In this case just post a patch updating rockchip-vpu.txt, CC-ing [email protected] and Rob Herring <[email protected]>.
Rob will Ack it, and then I can make a pull request for that bindings patch and this 16/16 patch. There is nothing wrong with this patch, so no need to repost. I just need to have an updated rockchip-vpu.txt patch as well.
Regards,
Hans
Quoted 26 lines
Regards,
JonasQuoted 21 lines
Regards,
Hans
Quoted 16 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0{ .compatible = "rockchip,rk3288-vpu", .data = &rk3288_vpu_variant, }, {/* sentinel */ } };drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h +1
-0@@ -79,6 +79,7 @@ enum rockchip_vpu_enc_fmt { };extern const struct rockchip_vpu_variant rk3399_vpu_variant; +extern const struct rockchip_vpu_variant rk3328_vpu_variant;extern const struct rockchip_vpu_variant rk3288_vpu_variant;void rockchip_vpu_watchdog (struct work_struct *work);
Re: [PATCH v6 16/16] rockchip/vpu: Add support for MPEG-2 decoding on RK3328
In reply to Jonas KarlmanQuoted 49 lines · Jonas Karlman
Quoted 48 lines · Hans Verkuil
Quoted 40 lines · Ezequiel Garcia
From: Jonas Karlman <[email protected]>
Add necessary bits to support MPEG2 decoding on RK3328.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]>--
Changes from v5:
* New patch.drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c | 12 ++++++++++++ .../staging/media/rockchip/vpu/rockchip_vpu_drv.c | 1 + drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h | 1 + 3 files changed, 14 insertions(+)drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c +12
-0@@ -175,3 +175,15 @@ const struct rockchip_vpu_variant rk3399_vpu_variant = { .clk_names = {"aclk", "hclk"}, .num_clocks = 2 }; + +const struct rockchip_vpu_variant rk3328_vpu_variant = { + .dec_offset =0x400 , + .dec_fmts = rk3399_vpu_dec_fmts, + .num_dec_fmts =ARRAY_SIZE (rk3399_vpu_dec_fmts), + .codec =RK_VPU_MPEG2_DECODER , + .codec_ops = rk3399_vpu_codec_ops, + .vdpu_irq = rk3399_vdpu_irq, + .init = rk3399_vpu_hw_init, + .clk_names = {"aclk" ,"hclk" }, + .num_clocks =2 +};drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +0
-0drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c static const struct v4l2_file_operations rockchip_vpu_fops = { · line 422
Quoted 4 lines
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c +1
-0@@ -419,6 +419,7 @@ static const struct v4l2_file_operations rockchip_vpu_fops = {static const struct of_device_id of_rockchip_vpu_match[] = { { .compatible ="rockchip,rk3399-vpu" , .data = &rk3399_vpu_variant, }, + { .compatible ="rockchip,rk3328-vpu" , .data = &rk3328_vpu_variant, },This new compatible string should be documented in
Documentation/devicetree/bindings/media/rockchip-vpu.txtas well.
Quoted 5 lines
Quoted 2 lines
I'll take patches 1-15 and drop this one. This patch can be merged once the bindings file is updated as well.
Looks like the bindings patch did not get picked for v6 :-)
Oh, that's my bad. I picked the support and left the binding out.
Quoted 4 lines
I am a bit unclear on how to handle patch submission that covers multiple subtrees. Should I send a single series including three patches: bindings update, this patch and device tree update? Or is a series with only bindings update and this patch preferred?
Thanks both for sorting this one out,
Ezequiel