Commit 21f0315b authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Mauro Carvalho Chehab
Browse files

hantro: Rework how encoder and decoder are identified



So far we've been using the .buf_finish hook to distinguish
decoder from encoder. This is unnecessarily obfuscated.

Moreover, we want to move the buf_finish, so use a cleaner
scheme to distinguish the driver decoder/encoder type.

Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Reviewed-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 4df3a47e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ struct hantro_dev {
 *
 * @dev:		VPU driver data to which the context belongs.
 * @fh:			V4L2 file handler.
 * @is_encoder:		Decoder or encoder context?
 *
 * @sequence_cap:       Sequence counter for capture queue
 * @sequence_out:       Sequence counter for output queue
@@ -223,6 +224,7 @@ struct hantro_dev {
struct hantro_ctx {
	struct hantro_dev *dev;
	struct v4l2_fh fh;
	bool is_encoder;

	u32 sequence_cap;
	u32 sequence_out;
@@ -399,8 +401,6 @@ static inline void hantro_reg_write_s(struct hantro_dev *vpu,
	vdpu_write(vpu, vdpu_read_mask(vpu, reg, val), reg->base);
}

bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx);

void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id);
dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts);

@@ -420,7 +420,7 @@ static inline bool
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 !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
}

static inline dma_addr_t
+3 −6
Original line number Diff line number Diff line
@@ -195,11 +195,6 @@ err_cancel_job:
	hantro_job_finish(ctx->dev, ctx, 0, VB2_BUF_STATE_ERROR);
}

bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
{
	return ctx->buf_finish == hantro_enc_buf_finish;
}

static struct v4l2_m2m_ops vpu_m2m_ops = {
	.device_run = device_run,
};
@@ -240,7 +235,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
	 *
	 * For the DMA destination buffer, we use a bounce buffer.
	 */
	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		dst_vq->mem_ops = &vb2_vmalloc_memops;
	} else {
		dst_vq->bidirectional = true;
@@ -420,8 +415,10 @@ static int hantro_open(struct file *filp)
	if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
		allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS;
		ctx->buf_finish = hantro_enc_buf_finish;
		ctx->is_encoder = true;
	} else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) {
		allowed_codecs = vpu->variant->codec & HANTRO_DECODERS;
		ctx->is_encoder = false;
	} else {
		ret = -ENODEV;
		goto err_ctx_free;
+14 −14
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
{
	const struct hantro_fmt *formats;

	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		formats = ctx->dev->variant->enc_fmts;
		*num_fmts = ctx->dev->variant->num_enc_fmts;
	} else {
@@ -55,7 +55,7 @@ static const struct hantro_fmt *
hantro_get_postproc_formats(const struct hantro_ctx *ctx,
			    unsigned int *num_fmts)
{
	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		*num_fmts = 0;
		return NULL;
	}
@@ -158,7 +158,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
	 *    not MODE_NONE.
	 *  - on the output side we want to filter out all MODE_NONE formats.
	 */
	skip_mode_none = capture == hantro_is_encoder_ctx(ctx);
	skip_mode_none = capture == ctx->is_encoder;

	formats = hantro_get_formats(ctx, &num_fmts);
	for (i = 0; i < num_fmts; i++) {
@@ -240,7 +240,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
	bool capture = V4L2_TYPE_IS_CAPTURE(type);
	bool coded;

	coded = capture == hantro_is_encoder_ctx(ctx);
	coded = capture == ctx->is_encoder;

	vpu_debug(4, "trying format %c%c%c%c\n",
		  (pix_mp->pixelformat & 0x7f),
@@ -257,7 +257,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
	if (coded) {
		pix_mp->num_planes = 1;
		vpu_fmt = fmt;
	} else if (hantro_is_encoder_ctx(ctx)) {
	} else if (ctx->is_encoder) {
		vpu_fmt = ctx->vpu_dst_fmt;
	} else {
		vpu_fmt = ctx->vpu_src_fmt;
@@ -330,7 +330,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)

	vpu_fmt = hantro_get_default_fmt(ctx, true);

	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		ctx->vpu_dst_fmt = vpu_fmt;
		fmt = &ctx->dst_fmt;
	} else {
@@ -341,7 +341,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
	hantro_reset_fmt(fmt, vpu_fmt);
	fmt->width = vpu_fmt->frmsize.min_width;
	fmt->height = vpu_fmt->frmsize.min_height;
	if (hantro_is_encoder_ctx(ctx))
	if (ctx->is_encoder)
		hantro_set_fmt_cap(ctx, fmt);
	else
		hantro_set_fmt_out(ctx, fmt);
@@ -355,7 +355,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx)

	raw_vpu_fmt = hantro_get_default_fmt(ctx, false);

	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		ctx->vpu_src_fmt = raw_vpu_fmt;
		raw_fmt = &ctx->src_fmt;
		encoded_fmt = &ctx->dst_fmt;
@@ -368,7 +368,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx)
	hantro_reset_fmt(raw_fmt, raw_vpu_fmt);
	raw_fmt->width = encoded_fmt->width;
	raw_fmt->width = encoded_fmt->width;
	if (hantro_is_encoder_ctx(ctx))
	if (ctx->is_encoder)
		hantro_set_fmt_out(ctx, raw_fmt);
	else
		hantro_set_fmt_cap(ctx, raw_fmt);
@@ -409,7 +409,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,
	if (ret)
		return ret;

	if (!hantro_is_encoder_ctx(ctx)) {
	if (!ctx->is_encoder) {
		struct vb2_queue *peer_vq;

		/*
@@ -450,7 +450,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,
	 * Note that hantro_reset_raw_fmt() also propagates size
	 * changes to the raw format.
	 */
	if (!hantro_is_encoder_ctx(ctx))
	if (!ctx->is_encoder)
		hantro_reset_raw_fmt(ctx);

	/* Colorimetry information are always propagated. */
@@ -479,7 +479,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
	if (vb2_is_busy(vq))
		return -EBUSY;

	if (hantro_is_encoder_ctx(ctx)) {
	if (ctx->is_encoder) {
		struct vb2_queue *peer_vq;

		/*
@@ -512,7 +512,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
	 * Note that hantro_reset_raw_fmt() also propagates size
	 * changes to the raw format.
	 */
	if (hantro_is_encoder_ctx(ctx))
	if (ctx->is_encoder)
		hantro_reset_raw_fmt(ctx);

	/* Colorimetry information are always propagated. */
@@ -655,7 +655,7 @@ static bool hantro_vq_is_coded(struct vb2_queue *q)
{
	struct hantro_ctx *ctx = vb2_get_drv_priv(q);

	return hantro_is_encoder_ctx(ctx) != V4L2_TYPE_IS_OUTPUT(q->type);
	return ctx->is_encoder != V4L2_TYPE_IS_OUTPUT(q->type);
}

static int hantro_start_streaming(struct vb2_queue *q, unsigned int count)