v4l: CB1 Too much media_proxy log while start playback. [1/1]

PD#SWPL-194559

Problem:
Too much media_proxy log while start playback.

Solution:
media_proxy init in vidioc_s_fmt.

Verify:
ohm

Change-Id: I816c6e9c2d0012369079ffa8336f327751fc393d
Signed-off-by: yu.xie <yu.xie@amlogic.com>
diff --git a/drivers/amvdec_ports/aml_vcodec_dec.c b/drivers/amvdec_ports/aml_vcodec_dec.c
index 9617c1a..6a7418a 100644
--- a/drivers/amvdec_ports/aml_vcodec_dec.c
+++ b/drivers/amvdec_ports/aml_vcodec_dec.c
@@ -3443,6 +3443,13 @@
 		return -EBUSY;
 	}
 
+#ifdef CONFIG_AMLOGIC_MEDIA_PROXY
+	if (V4L2_TYPE_IS_OUTPUT(f->type) && !ctx->k_producer_session)
+		media_proxy_produce_init(&ctx->k_producer_session,
+			AML_VCODEC_DEC_NAME,
+			MEDIA_VIDEO_METRICS_FRAME_DECODED_INFO);
+#endif
+
 	fmt = aml_vdec_find_format(f);
 	if (fmt == NULL) {
 		if (V4L2_TYPE_IS_OUTPUT(f->type))
@@ -3487,7 +3494,7 @@
 				v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
 					"vdec_if_init() fail ret=%d\n", ret);
 				mutex_unlock(&ctx->state_lock);
-				return -EINVAL;
+				goto S_FMT_ERROR;
 			}
 
 			vdec_trace_init(&ctx->vtr, ctx->id, vdec_get_vdec_id(ctx->ada_ctx));
@@ -3506,7 +3513,7 @@
 		if (!vdec_check_is_available(pix->pixelformat)) {
 			v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
 				"VC-1 only support single mode. \n");
-			return -EINVAL;
+			goto S_FMT_ERROR;
 		}
 
 		v4l_dbg(ctx, V4L_DEBUG_CODEC_EXINFO,
@@ -3527,7 +3534,7 @@
 				v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
 					"vdec_if_init() fail ret=%d\n", ret);
 				mutex_unlock(&ctx->state_lock);
-				return -EINVAL;
+				goto S_FMT_ERROR;
 			}
 
 			vdec_trace_init(&ctx->vtr, ctx->id, vdec_get_vdec_id(ctx->ada_ctx));
@@ -3550,6 +3557,13 @@
 	}
 
 	return 0;
+S_FMT_ERROR:
+#ifdef CONFIG_AMLOGIC_MEDIA_PROXY
+	if (ctx->k_producer_session)
+		media_proxy_produce_deinit(ctx->k_producer_session);
+#endif
+	return -EINVAL;
+
 }
 
 static int vidioc_enum_framesizes(struct file *file, void *priv,
diff --git a/drivers/amvdec_ports/aml_vcodec_dec_drv.c b/drivers/amvdec_ports/aml_vcodec_dec_drv.c
index 487a247..f9c7b52 100644
--- a/drivers/amvdec_ports/aml_vcodec_dec_drv.c
+++ b/drivers/amvdec_ports/aml_vcodec_dec_drv.c
@@ -119,6 +119,7 @@
 	atomic_set(&ctx->vpp_cache_num, 0);
 	atomic_set(&ctx->ge2d_cache_num, 0);
 	mutex_init(&ctx->v4l_intf_lock);
+	ctx->k_producer_session = NULL;
 
 	ctx->post_to_upper_done = true;
 	ctx->param_sets_from_ucode = param_sets_from_ucode ? 1 : 0;
@@ -134,13 +135,6 @@
 
 	ctx->type = AML_INST_DECODER;
 
-#ifdef CONFIG_AMLOGIC_MEDIA_PROXY
-	if (!ctx->k_producer_session)
-		media_proxy_produce_init(&ctx->k_producer_session,
-			AML_VCODEC_DEC_NAME,
-			MEDIA_VIDEO_METRICS_FRAME_DECODED_INFO);
-#endif
-
 	ret = aml_vcodec_dec_ctrls_setup(ctx);
 	if (ret) {
 		v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
@@ -211,10 +205,6 @@
 err_m2m_ctx_init:
 	v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
 err_ctrls_setup:
-#ifdef CONFIG_AMLOGIC_MEDIA_PROXY
-	if (ctx->k_producer_session)
-		media_proxy_produce_deinit(ctx->k_producer_session);
-#endif
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 	aml_media_mem_free(ctx->meta_infos.meta_bufs);