From c750ba048bc922d05afeedc9a87adfaf20756b51 Mon Sep 17 00:00:00 2001 From: Megha Byahatti Date: Mon, 20 Mar 2023 11:16:11 +0530 Subject: [PATCH] video: driver: add try_fmt allow checks inside state handler Remove msm_vidc_allow_s_fmt function and use state specific MSM_VIDC_TRY_FMT checks inside state_handler Change-Id: I405b9cfb89e4daadafcc05eb99e66e2b0aad328e Signed-off-by: Megha Byahatti --- driver/vidc/inc/msm_vidc_driver.h | 1 - driver/vidc/inc/msm_vidc_state.h | 1 + driver/vidc/src/msm_vidc.c | 3 --- driver/vidc/src/msm_vidc_driver.c | 32 ----------------------- driver/vidc/src/msm_vidc_state.c | 42 +++++++++++++++++++++++++++++++ driver/vidc/src/msm_vidc_v4l2.c | 2 +- 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/driver/vidc/inc/msm_vidc_driver.h b/driver/vidc/inc/msm_vidc_driver.h index 3991761329..8d3e3dffbf 100644 --- a/driver/vidc/inc/msm_vidc_driver.h +++ b/driver/vidc/inc/msm_vidc_driver.h @@ -485,7 +485,6 @@ struct msm_vidc_inst *get_inst_ref(struct msm_vidc_core *core, struct msm_vidc_inst *get_inst(struct msm_vidc_core *core, u32 session_id); void put_inst(struct msm_vidc_inst *inst); -bool msm_vidc_allow_s_fmt(struct msm_vidc_inst *inst, u32 type); bool msm_vidc_allow_metadata_delivery(struct msm_vidc_inst *inst, u32 cap_id, u32 port); bool msm_vidc_allow_metadata_subscription(struct msm_vidc_inst *inst, diff --git a/driver/vidc/inc/msm_vidc_state.h b/driver/vidc/inc/msm_vidc_state.h index 6dec161d3a..4b60e8a2d9 100644 --- a/driver/vidc/inc/msm_vidc_state.h +++ b/driver/vidc/inc/msm_vidc_state.h @@ -19,6 +19,7 @@ struct msm_vidc_core; } #define FOREACH_EVENT(EVENT) { \ + EVENT(TRY_FMT) \ EVENT(S_FMT) \ EVENT(REQBUFS) \ EVENT(S_CTRL) \ diff --git a/driver/vidc/src/msm_vidc.c b/driver/vidc/src/msm_vidc.c index 0422842e96..80f710e846 100644 --- a/driver/vidc/src/msm_vidc.c +++ b/driver/vidc/src/msm_vidc.c @@ -228,9 +228,6 @@ int msm_vidc_try_fmt(void *instance, struct v4l2_format *f) return -EINVAL; } - if (!msm_vidc_allow_s_fmt(inst, f->type)) - return -EBUSY; - if (inst->domain == MSM_VIDC_DECODER) rc = msm_vdec_try_fmt(inst, f); if (inst->domain == MSM_VIDC_ENCODER) diff --git a/driver/vidc/src/msm_vidc_driver.c b/driver/vidc/src/msm_vidc_driver.c index 7f594be6da..ec1bfe7aad 100644 --- a/driver/vidc/src/msm_vidc_driver.c +++ b/driver/vidc/src/msm_vidc_driver.c @@ -958,38 +958,6 @@ int signal_session_msg_receipt(struct msm_vidc_inst *inst, return 0; } -bool msm_vidc_allow_s_fmt(struct msm_vidc_inst *inst, u32 type) -{ - bool allow = false; - - if (!inst) { - d_vpr_e("%s: invalid params\n", __func__); - return false; - } - if (is_state(inst, MSM_VIDC_OPEN)) { - allow = true; - goto exit; - } - if (type == OUTPUT_MPLANE || type == OUTPUT_META_PLANE) { - if (is_state(inst, MSM_VIDC_INPUT_STREAMING)) { - allow = true; - goto exit; - } - } - if (type == INPUT_MPLANE || type == INPUT_META_PLANE) { - if (is_state(inst, MSM_VIDC_OUTPUT_STREAMING)) { - allow = true; - goto exit; - } - } - -exit: - if (!allow) - i_vpr_e(inst, "%s: type %d not allowed in state %s\n", - __func__, type, state_name(inst->state)); - return allow; -} - bool msm_vidc_allow_metadata_delivery(struct msm_vidc_inst *inst, u32 cap_id, u32 port) { diff --git a/driver/vidc/src/msm_vidc_state.c b/driver/vidc/src/msm_vidc_state.c index ec9d30bcd2..bddff5f5f2 100644 --- a/driver/vidc/src/msm_vidc_state.c +++ b/driver/vidc/src/msm_vidc_state.c @@ -656,6 +656,16 @@ static int msm_vidc_open_state(struct msm_vidc_inst *inst, } switch (event) { + case MSM_VIDC_TRY_FMT: + { + struct v4l2_format *f = (struct v4l2_format *)data; + + /* allow try_fmt request in open state */ + rc = msm_vidc_try_fmt(inst, f); + if (rc) + return rc; + break; + } case MSM_VIDC_S_FMT: { struct v4l2_format *f = (struct v4l2_format *)data; @@ -783,6 +793,22 @@ static int msm_vidc_input_streaming_state(struct msm_vidc_inst *inst, return rc; break; } + case MSM_VIDC_TRY_FMT: + { + struct v4l2_format *f = (struct v4l2_format *)data; + + /* disallow */ + if (f->type == INPUT_MPLANE || f->type == INPUT_META_PLANE) { + i_vpr_e(inst, "%s: (%s) not allowed for (%s) port\n", + __func__, event_name(event), v4l2_type_name(f->type)); + return -EBUSY; + } + + rc = msm_vidc_try_fmt(inst, f); + if (rc) + return rc; + break; + } case MSM_VIDC_S_FMT: { struct v4l2_format *f = (struct v4l2_format *)data; @@ -969,6 +995,22 @@ static int msm_vidc_output_streaming_state(struct msm_vidc_inst *inst, return rc; break; } + case MSM_VIDC_TRY_FMT: + { + struct v4l2_format *f = (struct v4l2_format *)data; + + /* disallow */ + if (f->type == OUTPUT_MPLANE || f->type == OUTPUT_META_PLANE) { + i_vpr_e(inst, "%s: (%s) not allowed for (%s) port\n", + __func__, event_name(event), v4l2_type_name(f->type)); + return -EBUSY; + } + + rc = msm_vidc_try_fmt(inst, f); + if (rc) + return rc; + break; + } case MSM_VIDC_S_FMT: { struct v4l2_format *f = (struct v4l2_format *)data; diff --git a/driver/vidc/src/msm_vidc_v4l2.c b/driver/vidc/src/msm_vidc_v4l2.c index 8e797786f9..ab916c43d3 100644 --- a/driver/vidc/src/msm_vidc_v4l2.c +++ b/driver/vidc/src/msm_vidc_v4l2.c @@ -135,7 +135,7 @@ int msm_v4l2_try_fmt(struct file *filp, void *fh, struct v4l2_format *f) rc = -EBUSY; goto unlock; } - rc = msm_vidc_try_fmt((void *)inst, f); + rc = inst->event_handle(inst, MSM_VIDC_TRY_FMT, f); if (rc) goto unlock;