mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
media: hantro: Refactor for V4L2 API spec compliancy
Refactor how S_FMT and TRY_FMT are handled, and also make sure internal initial format and format reset are done properly. The latter is achieved by making sure the same hantro_{set,try}_fmt helpers are called on all paths that set the format (which is part of the driver state). This commit removes the following v4l2-compliance warnings: test VIDIOC_G_FMT: OK fail: v4l2-test-formats.cpp(711): Video Capture Multiplanar: TRY_FMT(G_FMT) != G_FMT test VIDIOC_TRY_FMT: FAIL fail: v4l2-test-formats.cpp(1116): Video Capture Multiplanar: S_FMT(G_FMT) != G_FMT test VIDIOC_S_FMT: FAIL Reported-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
parent
774ffd751a
commit
88d06362d1
@ -417,7 +417,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
hantro_needs_postproc(struct hantro_ctx *ctx, const struct hantro_fmt *fmt)
|
hantro_needs_postproc(const struct hantro_ctx *ctx,
|
||||||
|
const struct hantro_fmt *fmt)
|
||||||
{
|
{
|
||||||
return !hantro_is_encoder_ctx(ctx) && fmt->fourcc != V4L2_PIX_FMT_NV12;
|
return !hantro_is_encoder_ctx(ctx) && fmt->fourcc != V4L2_PIX_FMT_NV12;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@
|
|||||||
#include "hantro_hw.h"
|
#include "hantro_hw.h"
|
||||||
#include "hantro_v4l2.h"
|
#include "hantro_v4l2.h"
|
||||||
|
|
||||||
|
static int hantro_set_fmt_out(struct hantro_ctx *ctx,
|
||||||
|
struct v4l2_pix_format_mplane *pix_mp);
|
||||||
|
static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
|
||||||
|
struct v4l2_pix_format_mplane *pix_mp);
|
||||||
|
|
||||||
static const struct hantro_fmt *
|
static const struct hantro_fmt *
|
||||||
hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
|
hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
|
||||||
{
|
{
|
||||||
@ -227,12 +232,12 @@ static int vidioc_g_fmt_cap_mplane(struct file *file, void *priv,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f,
|
static int hantro_try_fmt(const struct hantro_ctx *ctx,
|
||||||
bool capture)
|
struct v4l2_pix_format_mplane *pix_mp,
|
||||||
|
enum v4l2_buf_type type)
|
||||||
{
|
{
|
||||||
struct hantro_ctx *ctx = fh_to_ctx(priv);
|
|
||||||
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
|
|
||||||
const struct hantro_fmt *fmt, *vpu_fmt;
|
const struct hantro_fmt *fmt, *vpu_fmt;
|
||||||
|
bool capture = !V4L2_TYPE_IS_OUTPUT(type);
|
||||||
bool coded;
|
bool coded;
|
||||||
|
|
||||||
coded = capture == hantro_is_encoder_ctx(ctx);
|
coded = capture == hantro_is_encoder_ctx(ctx);
|
||||||
@ -246,7 +251,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f,
|
|||||||
fmt = hantro_find_format(ctx, pix_mp->pixelformat);
|
fmt = hantro_find_format(ctx, pix_mp->pixelformat);
|
||||||
if (!fmt) {
|
if (!fmt) {
|
||||||
fmt = hantro_get_default_fmt(ctx, coded);
|
fmt = hantro_get_default_fmt(ctx, coded);
|
||||||
f->fmt.pix_mp.pixelformat = fmt->fourcc;
|
pix_mp->pixelformat = fmt->fourcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coded) {
|
if (coded) {
|
||||||
@ -294,13 +299,13 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f,
|
|||||||
static int vidioc_try_fmt_cap_mplane(struct file *file, void *priv,
|
static int vidioc_try_fmt_cap_mplane(struct file *file, void *priv,
|
||||||
struct v4l2_format *f)
|
struct v4l2_format *f)
|
||||||
{
|
{
|
||||||
return vidioc_try_fmt(file, priv, f, true);
|
return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vidioc_try_fmt_out_mplane(struct file *file, void *priv,
|
static int vidioc_try_fmt_out_mplane(struct file *file, void *priv,
|
||||||
struct v4l2_format *f)
|
struct v4l2_format *f)
|
||||||
{
|
{
|
||||||
return vidioc_try_fmt(file, priv, f, false);
|
return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -334,11 +339,12 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hantro_reset_fmt(fmt, vpu_fmt);
|
hantro_reset_fmt(fmt, vpu_fmt);
|
||||||
fmt->num_planes = 1;
|
|
||||||
fmt->width = vpu_fmt->frmsize.min_width;
|
fmt->width = vpu_fmt->frmsize.min_width;
|
||||||
fmt->height = vpu_fmt->frmsize.min_height;
|
fmt->height = vpu_fmt->frmsize.min_height;
|
||||||
fmt->plane_fmt[0].sizeimage = vpu_fmt->header_size +
|
if (hantro_is_encoder_ctx(ctx))
|
||||||
fmt->width * fmt->height * vpu_fmt->max_depth;
|
hantro_set_fmt_cap(ctx, fmt);
|
||||||
|
else
|
||||||
|
hantro_set_fmt_out(ctx, fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -360,9 +366,12 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hantro_reset_fmt(raw_fmt, raw_vpu_fmt);
|
hantro_reset_fmt(raw_fmt, raw_vpu_fmt);
|
||||||
v4l2_fill_pixfmt_mp(raw_fmt, raw_vpu_fmt->fourcc,
|
raw_fmt->width = encoded_fmt->width;
|
||||||
encoded_fmt->width,
|
raw_fmt->width = encoded_fmt->width;
|
||||||
encoded_fmt->height);
|
if (hantro_is_encoder_ctx(ctx))
|
||||||
|
hantro_set_fmt_out(ctx, raw_fmt);
|
||||||
|
else
|
||||||
|
hantro_set_fmt_cap(ctx, raw_fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hantro_reset_fmts(struct hantro_ctx *ctx)
|
void hantro_reset_fmts(struct hantro_ctx *ctx)
|
||||||
@ -388,15 +397,15 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 fourcc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int hantro_set_fmt_out(struct hantro_ctx *ctx,
|
||||||
vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
|
struct v4l2_pix_format_mplane *pix_mp)
|
||||||
{
|
{
|
||||||
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
|
struct vb2_queue *vq;
|
||||||
struct hantro_ctx *ctx = fh_to_ctx(priv);
|
|
||||||
struct vb2_queue *vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = vidioc_try_fmt_out_mplane(file, priv, f);
|
vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
|
||||||
|
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
|
||||||
|
ret = hantro_try_fmt(ctx, pix_mp, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -458,16 +467,15 @@ vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv,
|
static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
|
||||||
struct v4l2_format *f)
|
struct v4l2_pix_format_mplane *pix_mp)
|
||||||
{
|
{
|
||||||
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
|
|
||||||
struct hantro_ctx *ctx = fh_to_ctx(priv);
|
|
||||||
struct vb2_queue *vq;
|
struct vb2_queue *vq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Change not allowed if queue is busy. */
|
/* Change not allowed if queue is busy. */
|
||||||
vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
|
vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
|
||||||
|
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
|
||||||
if (vb2_is_busy(vq))
|
if (vb2_is_busy(vq))
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
@ -488,7 +496,7 @@ static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv,
|
|||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vidioc_try_fmt_cap_mplane(file, priv, f);
|
ret = hantro_try_fmt(ctx, pix_mp, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -522,6 +530,18 @@ static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
|
||||||
|
{
|
||||||
|
return hantro_set_fmt_out(fh_to_ctx(priv), &f->fmt.pix_mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vidioc_s_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f)
|
||||||
|
{
|
||||||
|
return hantro_set_fmt_cap(fh_to_ctx(priv), &f->fmt.pix_mp);
|
||||||
|
}
|
||||||
|
|
||||||
const struct v4l2_ioctl_ops hantro_ioctl_ops = {
|
const struct v4l2_ioctl_ops hantro_ioctl_ops = {
|
||||||
.vidioc_querycap = vidioc_querycap,
|
.vidioc_querycap = vidioc_querycap,
|
||||||
.vidioc_enum_framesizes = vidioc_enum_framesizes,
|
.vidioc_enum_framesizes = vidioc_enum_framesizes,
|
||||||
|
Loading…
Reference in New Issue
Block a user