mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 15:41:52 +02:00
media: iris: Add support for ENUM_FMT, S/G/TRY_FMT encoder
Add V4L2 format handling support for the encoder by adding implementation of ENUM/S/G/TRY_FMT with necessary hooks. This ensures that the encoder supports format negotiation consistent with V4L2 expectation, enabling userspace applications to configure resolution, pixel format and buffer layout properly. Tested-by: Vikash Garodia <quic_vgarodia@quicinc.com> # X1E80100 Reviewed-by: Vikash Garodia <quic_vgarodia@quicinc.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-HDK Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-HDK Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # x1e80100-crd Signed-off-by: Bryan O'Donoghue <bod@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
This commit is contained in:
parent
5ad964ad56
commit
63357cf8a9
|
|
@ -40,7 +40,8 @@ enum domain_type {
|
|||
* @vdev_dec: iris video device structure for decoder
|
||||
* @vdev_enc: iris video device structure for encoder
|
||||
* @iris_v4l2_file_ops: iris v4l2 file ops
|
||||
* @iris_v4l2_ioctl_ops: iris v4l2 ioctl ops
|
||||
* @iris_v4l2_ioctl_ops_dec: iris v4l2 ioctl ops for decoder
|
||||
* @iris_v4l2_ioctl_ops_enc: iris v4l2 ioctl ops for encoder
|
||||
* @iris_vb2_ops: iris vb2 ops
|
||||
* @icc_tbl: table of iris interconnects
|
||||
* @icc_count: count of iris interconnects
|
||||
|
|
@ -81,7 +82,8 @@ struct iris_core {
|
|||
struct video_device *vdev_dec;
|
||||
struct video_device *vdev_enc;
|
||||
const struct v4l2_file_operations *iris_v4l2_file_ops;
|
||||
const struct v4l2_ioctl_ops *iris_v4l2_ioctl_ops;
|
||||
const struct v4l2_ioctl_ops *iris_v4l2_ioctl_ops_dec;
|
||||
const struct v4l2_ioctl_ops *iris_v4l2_ioctl_ops_enc;
|
||||
const struct vb2_ops *iris_vb2_ops;
|
||||
struct icc_bulk_data *icc_tbl;
|
||||
u32 icc_count;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@
|
|||
#define DEFAULT_WIDTH 320
|
||||
#define DEFAULT_HEIGHT 240
|
||||
|
||||
enum iris_fmt_type {
|
||||
IRIS_FMT_H264,
|
||||
IRIS_FMT_HEVC,
|
||||
IRIS_FMT_VP9,
|
||||
};
|
||||
|
||||
struct iris_fmt {
|
||||
u32 pixfmt;
|
||||
u32 type;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct iris_inst - holds per video instance parameters
|
||||
*
|
||||
|
|
|
|||
|
|
@ -157,16 +157,17 @@ static int iris_register_video_device(struct iris_core *core, enum domain_type t
|
|||
|
||||
vdev->release = video_device_release;
|
||||
vdev->fops = core->iris_v4l2_file_ops;
|
||||
vdev->ioctl_ops = core->iris_v4l2_ioctl_ops;
|
||||
vdev->vfl_dir = VFL_DIR_M2M;
|
||||
vdev->v4l2_dev = &core->v4l2_dev;
|
||||
vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
|
||||
|
||||
if (type == DECODER) {
|
||||
strscpy(vdev->name, "qcom-iris-decoder", sizeof(vdev->name));
|
||||
vdev->ioctl_ops = core->iris_v4l2_ioctl_ops_dec;
|
||||
core->vdev_dec = vdev;
|
||||
} else if (type == ENCODER) {
|
||||
strscpy(vdev->name, "qcom-iris-encoder", sizeof(vdev->name));
|
||||
vdev->ioctl_ops = core->iris_v4l2_ioctl_ops_enc;
|
||||
core->vdev_enc = vdev;
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
|
|
|
|||
|
|
@ -8,17 +8,6 @@
|
|||
|
||||
struct iris_inst;
|
||||
|
||||
enum iris_fmt_type {
|
||||
IRIS_FMT_H264,
|
||||
IRIS_FMT_HEVC,
|
||||
IRIS_FMT_VP9,
|
||||
};
|
||||
|
||||
struct iris_fmt {
|
||||
u32 pixfmt;
|
||||
u32 type;
|
||||
};
|
||||
|
||||
int iris_vdec_inst_init(struct iris_inst *inst);
|
||||
void iris_vdec_inst_deinit(struct iris_inst *inst);
|
||||
int iris_vdec_enum_fmt(struct iris_inst *inst, struct v4l2_fmtdesc *f);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
* Copyright (c) 2022-2025 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <media/v4l2-mem2mem.h>
|
||||
|
||||
#include "iris_buffer.h"
|
||||
#include "iris_instance.h"
|
||||
#include "iris_venc.h"
|
||||
|
|
@ -14,8 +16,11 @@ int iris_venc_inst_init(struct iris_inst *inst)
|
|||
|
||||
inst->fmt_src = kzalloc(sizeof(*inst->fmt_src), GFP_KERNEL);
|
||||
inst->fmt_dst = kzalloc(sizeof(*inst->fmt_dst), GFP_KERNEL);
|
||||
if (!inst->fmt_src || !inst->fmt_dst)
|
||||
if (!inst->fmt_src || !inst->fmt_dst) {
|
||||
kfree(inst->fmt_src);
|
||||
kfree(inst->fmt_dst);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
f = inst->fmt_dst;
|
||||
f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
|
||||
|
|
@ -63,3 +68,208 @@ void iris_venc_inst_deinit(struct iris_inst *inst)
|
|||
kfree(inst->fmt_dst);
|
||||
kfree(inst->fmt_src);
|
||||
}
|
||||
|
||||
static const struct iris_fmt iris_venc_formats[] = {
|
||||
[IRIS_FMT_H264] = {
|
||||
.pixfmt = V4L2_PIX_FMT_H264,
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
|
||||
},
|
||||
[IRIS_FMT_HEVC] = {
|
||||
.pixfmt = V4L2_PIX_FMT_HEVC,
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct iris_fmt *
|
||||
find_format(struct iris_inst *inst, u32 pixfmt, u32 type)
|
||||
{
|
||||
const struct iris_fmt *fmt = iris_venc_formats;
|
||||
unsigned int size = ARRAY_SIZE(iris_venc_formats);
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (fmt[i].pixfmt == pixfmt)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == size || fmt[i].type != type)
|
||||
return NULL;
|
||||
|
||||
return &fmt[i];
|
||||
}
|
||||
|
||||
static const struct iris_fmt *
|
||||
find_format_by_index(struct iris_inst *inst, u32 index, u32 type)
|
||||
{
|
||||
const struct iris_fmt *fmt = iris_venc_formats;
|
||||
unsigned int size = ARRAY_SIZE(iris_venc_formats);
|
||||
|
||||
if (index >= size || fmt[index].type != type)
|
||||
return NULL;
|
||||
|
||||
return &fmt[index];
|
||||
}
|
||||
|
||||
int iris_venc_enum_fmt(struct iris_inst *inst, struct v4l2_fmtdesc *f)
|
||||
{
|
||||
const struct iris_fmt *fmt;
|
||||
|
||||
switch (f->type) {
|
||||
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
|
||||
if (f->index)
|
||||
return -EINVAL;
|
||||
f->pixelformat = V4L2_PIX_FMT_NV12;
|
||||
break;
|
||||
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
|
||||
fmt = find_format_by_index(inst, f->index, f->type);
|
||||
if (!fmt)
|
||||
return -EINVAL;
|
||||
|
||||
f->pixelformat = fmt->pixfmt;
|
||||
f->flags = V4L2_FMT_FLAG_COMPRESSED | V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iris_venc_try_fmt(struct iris_inst *inst, struct v4l2_format *f)
|
||||
{
|
||||
struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
|
||||
const struct iris_fmt *fmt;
|
||||
struct v4l2_format *f_inst;
|
||||
|
||||
memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
|
||||
fmt = find_format(inst, pixmp->pixelformat, f->type);
|
||||
switch (f->type) {
|
||||
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
|
||||
if (f->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_NV12) {
|
||||
f_inst = inst->fmt_src;
|
||||
f->fmt.pix_mp.width = f_inst->fmt.pix_mp.width;
|
||||
f->fmt.pix_mp.height = f_inst->fmt.pix_mp.height;
|
||||
f->fmt.pix_mp.pixelformat = f_inst->fmt.pix_mp.pixelformat;
|
||||
}
|
||||
break;
|
||||
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
|
||||
if (!fmt) {
|
||||
f_inst = inst->fmt_dst;
|
||||
f->fmt.pix_mp.width = f_inst->fmt.pix_mp.width;
|
||||
f->fmt.pix_mp.height = f_inst->fmt.pix_mp.height;
|
||||
f->fmt.pix_mp.pixelformat = f_inst->fmt.pix_mp.pixelformat;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (pixmp->field == V4L2_FIELD_ANY)
|
||||
pixmp->field = V4L2_FIELD_NONE;
|
||||
|
||||
pixmp->num_planes = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iris_venc_s_fmt_output(struct iris_inst *inst, struct v4l2_format *f)
|
||||
{
|
||||
struct v4l2_format *fmt;
|
||||
|
||||
iris_venc_try_fmt(inst, f);
|
||||
|
||||
if (!(find_format(inst, f->fmt.pix_mp.pixelformat, f->type)))
|
||||
return -EINVAL;
|
||||
|
||||
fmt = inst->fmt_dst;
|
||||
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
|
||||
fmt->fmt.pix_mp.num_planes = 1;
|
||||
fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
|
||||
fmt->fmt.pix_mp.plane_fmt[0].sizeimage = iris_get_buffer_size(inst, BUF_OUTPUT);
|
||||
|
||||
if (f->fmt.pix_mp.colorspace != V4L2_COLORSPACE_DEFAULT &&
|
||||
f->fmt.pix_mp.colorspace != V4L2_COLORSPACE_REC709)
|
||||
f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_DEFAULT;
|
||||
fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
|
||||
fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
|
||||
fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
|
||||
fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
|
||||
|
||||
inst->buffers[BUF_OUTPUT].min_count = iris_vpu_buf_count(inst, BUF_OUTPUT);
|
||||
inst->buffers[BUF_OUTPUT].size = fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
|
||||
fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
|
||||
inst->codec = f->fmt.pix_mp.pixelformat;
|
||||
memcpy(f, fmt, sizeof(struct v4l2_format));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iris_venc_s_fmt_input(struct iris_inst *inst, struct v4l2_format *f)
|
||||
{
|
||||
struct v4l2_format *fmt, *output_fmt;
|
||||
|
||||
iris_venc_try_fmt(inst, f);
|
||||
|
||||
if (f->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_NV12)
|
||||
return -EINVAL;
|
||||
|
||||
fmt = inst->fmt_src;
|
||||
fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
|
||||
fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, 128);
|
||||
fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, 32);
|
||||
fmt->fmt.pix_mp.num_planes = 1;
|
||||
fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
|
||||
fmt->fmt.pix_mp.plane_fmt[0].bytesperline = ALIGN(f->fmt.pix_mp.width, 128);
|
||||
fmt->fmt.pix_mp.plane_fmt[0].sizeimage = iris_get_buffer_size(inst, BUF_INPUT);
|
||||
|
||||
fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
|
||||
fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
|
||||
fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
|
||||
fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
|
||||
|
||||
output_fmt = inst->fmt_dst;
|
||||
output_fmt->fmt.pix_mp.width = fmt->fmt.pix_mp.width;
|
||||
output_fmt->fmt.pix_mp.height = fmt->fmt.pix_mp.height;
|
||||
output_fmt->fmt.pix_mp.colorspace = fmt->fmt.pix_mp.colorspace;
|
||||
output_fmt->fmt.pix_mp.xfer_func = fmt->fmt.pix_mp.xfer_func;
|
||||
output_fmt->fmt.pix_mp.ycbcr_enc = fmt->fmt.pix_mp.ycbcr_enc;
|
||||
output_fmt->fmt.pix_mp.quantization = fmt->fmt.pix_mp.quantization;
|
||||
|
||||
inst->buffers[BUF_INPUT].min_count = iris_vpu_buf_count(inst, BUF_INPUT);
|
||||
inst->buffers[BUF_INPUT].size = fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
|
||||
|
||||
if (f->fmt.pix_mp.width != inst->crop.width ||
|
||||
f->fmt.pix_mp.height != inst->crop.height) {
|
||||
inst->crop.top = 0;
|
||||
inst->crop.left = 0;
|
||||
inst->crop.width = fmt->fmt.pix_mp.width;
|
||||
inst->crop.height = fmt->fmt.pix_mp.height;
|
||||
|
||||
iris_venc_s_fmt_output(inst, output_fmt);
|
||||
}
|
||||
|
||||
memcpy(f, fmt, sizeof(struct v4l2_format));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iris_venc_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
|
||||
{
|
||||
struct vb2_queue *q;
|
||||
|
||||
q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
|
||||
if (!q)
|
||||
return -EINVAL;
|
||||
|
||||
if (vb2_is_busy(q))
|
||||
return -EBUSY;
|
||||
|
||||
switch (f->type) {
|
||||
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
|
||||
return iris_venc_s_fmt_input(inst, f);
|
||||
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
|
||||
return iris_venc_s_fmt_output(inst, f);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,8 @@ struct iris_inst;
|
|||
|
||||
int iris_venc_inst_init(struct iris_inst *inst);
|
||||
void iris_venc_inst_deinit(struct iris_inst *inst);
|
||||
int iris_venc_enum_fmt(struct iris_inst *inst, struct v4l2_fmtdesc *f);
|
||||
int iris_venc_try_fmt(struct iris_inst *inst, struct v4l2_format *f);
|
||||
int iris_venc_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -306,16 +306,26 @@ static int iris_enum_fmt(struct file *filp, void *fh, struct v4l2_fmtdesc *f)
|
|||
{
|
||||
struct iris_inst *inst = iris_get_inst(filp);
|
||||
|
||||
return iris_vdec_enum_fmt(inst, f);
|
||||
if (inst->domain == DECODER)
|
||||
return iris_vdec_enum_fmt(inst, f);
|
||||
else if (inst->domain == ENCODER)
|
||||
return iris_venc_enum_fmt(inst, f);
|
||||
else
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int iris_try_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_format *f)
|
||||
{
|
||||
struct iris_inst *inst = iris_get_inst(filp);
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&inst->lock);
|
||||
ret = iris_vdec_try_fmt(inst, f);
|
||||
|
||||
if (inst->domain == DECODER)
|
||||
ret = iris_vdec_try_fmt(inst, f);
|
||||
else if (inst->domain == ENCODER)
|
||||
ret = iris_venc_try_fmt(inst, f);
|
||||
|
||||
mutex_unlock(&inst->lock);
|
||||
|
||||
return ret;
|
||||
|
|
@ -324,10 +334,15 @@ static int iris_try_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_form
|
|||
static int iris_s_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_format *f)
|
||||
{
|
||||
struct iris_inst *inst = iris_get_inst(filp);
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&inst->lock);
|
||||
ret = iris_vdec_s_fmt(inst, f);
|
||||
|
||||
if (inst->domain == DECODER)
|
||||
ret = iris_vdec_s_fmt(inst, f);
|
||||
else if (inst->domain == ENCODER)
|
||||
ret = iris_venc_s_fmt(inst, f);
|
||||
|
||||
mutex_unlock(&inst->lock);
|
||||
|
||||
return ret;
|
||||
|
|
@ -471,7 +486,7 @@ static const struct vb2_ops iris_vb2_ops = {
|
|||
.buf_queue = iris_vb2_buf_queue,
|
||||
};
|
||||
|
||||
static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops = {
|
||||
static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops_dec = {
|
||||
.vidioc_enum_fmt_vid_cap = iris_enum_fmt,
|
||||
.vidioc_enum_fmt_vid_out = iris_enum_fmt,
|
||||
.vidioc_try_fmt_vid_cap_mplane = iris_try_fmt_vid_mplane,
|
||||
|
|
@ -499,9 +514,21 @@ static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops = {
|
|||
.vidioc_decoder_cmd = iris_dec_cmd,
|
||||
};
|
||||
|
||||
static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops_enc = {
|
||||
.vidioc_enum_fmt_vid_cap = iris_enum_fmt,
|
||||
.vidioc_enum_fmt_vid_out = iris_enum_fmt,
|
||||
.vidioc_try_fmt_vid_cap_mplane = iris_try_fmt_vid_mplane,
|
||||
.vidioc_try_fmt_vid_out_mplane = iris_try_fmt_vid_mplane,
|
||||
.vidioc_s_fmt_vid_cap_mplane = iris_s_fmt_vid_mplane,
|
||||
.vidioc_s_fmt_vid_out_mplane = iris_s_fmt_vid_mplane,
|
||||
.vidioc_g_fmt_vid_cap_mplane = iris_g_fmt_vid_mplane,
|
||||
.vidioc_g_fmt_vid_out_mplane = iris_g_fmt_vid_mplane,
|
||||
};
|
||||
|
||||
void iris_init_ops(struct iris_core *core)
|
||||
{
|
||||
core->iris_v4l2_file_ops = &iris_v4l2_file_ops;
|
||||
core->iris_vb2_ops = &iris_vb2_ops;
|
||||
core->iris_v4l2_ioctl_ops = &iris_v4l2_ioctl_ops;
|
||||
core->iris_v4l2_ioctl_ops_dec = &iris_v4l2_ioctl_ops_dec;
|
||||
core->iris_v4l2_ioctl_ops_enc = &iris_v4l2_ioctl_ops_enc;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user