diff mbox series

[13/14] media: vicodec: Add support for stateless encoder

Message ID 20190330204311.107417-14-dafna3@gmail.com (mailing list archive)
State New, archived
Headers show
Series add support for stateless encoder | expand

Commit Message

Dafna Hirschfeld March 30, 2019, 8:43 p.m. UTC
Adjust the stateless API code to support
both encoder and decoder.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
---
 drivers/media/platform/vicodec/vicodec-core.c | 58 +++++++++++--------
 1 file changed, 33 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/vicodec/vicodec-core.c b/drivers/media/platform/vicodec/vicodec-core.c
index f042c4b618ba..3808e72b2361 100644
--- a/drivers/media/platform/vicodec/vicodec-core.c
+++ b/drivers/media/platform/vicodec/vicodec-core.c
@@ -280,29 +280,31 @@  static int device_process(struct vicodec_ctx *ctx,
 
 		ctx->state.header.size =
 			htonl(vb2_get_plane_payload(&src_vb->vb2_buf, 0));
-		/*
-		 * set the reference buffer from the reference timestamp
-		 * only if this is a P-frame
-		 */
-		if (!(ntohl(ctx->state.header.flags) & FWHT_FL_I_FRAME)) {
-			struct vb2_buffer *ref_vb2_buf;
-			int ref_buf_idx;
-			struct vb2_queue *vq_cap =
+		if (!ctx->is_enc) {
+			/*
+			 * set the reference buffer from the reference timestamp
+			 * only if this is a P-frame
+			*/
+			if (!(ntohl(ctx->state.header.flags) & FWHT_FL_I_FRAME)) {
+				struct vb2_buffer *ref_vb2_buf;
+				int ref_buf_idx;
+				struct vb2_queue *vq_cap =
 				v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
-						V4L2_BUF_TYPE_VIDEO_CAPTURE);
+				V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
-			ref_buf_idx = vb2_find_timestamp(vq_cap,
-							 ctx->state.ref_frame_ts, 0);
-			if (ref_buf_idx < 0)
-				return -EINVAL;
+				ref_buf_idx = vb2_find_timestamp(vq_cap,
+				ctx->state.ref_frame_ts, 0);
+				if (ref_buf_idx < 0)
+					return -EINVAL;
 
-			ref_vb2_buf = vq_cap->bufs[ref_buf_idx];
-			if (ref_vb2_buf->state == VB2_BUF_STATE_ERROR)
-				ret = -EINVAL;
-			ctx->state.ref_frame.buf =
+				ref_vb2_buf = vq_cap->bufs[ref_buf_idx];
+				if (ref_vb2_buf->state == VB2_BUF_STATE_ERROR)
+					ret = -EINVAL;
+				ctx->state.ref_frame.buf =
 				vb2_plane_vaddr(ref_vb2_buf, 0);
-		} else {
-			ctx->state.ref_frame.buf = NULL;
+			} else {
+				ctx->state.ref_frame.buf = NULL;
+			}
 		}
 	}
 	p_dst = vb2_plane_vaddr(&dst_vb->vb2_buf, 0);
@@ -1722,7 +1724,7 @@  static void vicodec_stop_streaming(struct vb2_queue *q)
 
 	if ((!V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) ||
 	    (V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc)) {
-		if (!ctx->is_stateless)
+		if (!ctx->is_stateless || ctx->is_enc)
 			kvfree(ctx->state.ref_frame.buf);
 		ctx->state.ref_frame.buf = NULL;
 		ctx->state.ref_frame.luma = NULL;
@@ -1800,20 +1802,26 @@  static int vicodec_try_ctrl(struct v4l2_ctrl *ctrl)
 	struct vicodec_ctx *ctx = container_of(ctrl->handler,
 			struct vicodec_ctx, hdl);
 	const struct v4l2_ctrl_fwht_params *params;
-	struct vicodec_q_data *q_dst = get_q_data(ctx,
-			V4L2_BUF_TYPE_VIDEO_CAPTURE);
+	struct vicodec_q_data *q_data;
+
+	if (ctx->is_enc)
+		q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+	else
+		q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
 	switch (ctrl->id) {
 	case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
 		params = ctrl->p_new.p_fwht_params;
-		if (params->width > q_dst->coded_width ||
+		if (params->width > q_data->coded_width ||
 		    params->width < MIN_WIDTH ||
-		    params->height > q_dst->coded_height ||
+		    params->height > q_data->coded_height ||
 		    params->height < MIN_HEIGHT)
 			return -EINVAL;
+		if (ctx->is_enc)
+			return 0;
 		if (!validate_by_version(params->flags, params->version))
 			return -EINVAL;
-		if (!validate_stateless_params_flags(params, q_dst->info))
+		if (!validate_stateless_params_flags(params, q_data->info))
 			return -EINVAL;
 		return 0;
 	default: