media: venus: Mark last capture buffer
authorStanimir Varbanov <stanimir.varbanov@linaro.org>
Fri, 3 Apr 2020 15:56:29 +0000 (17:56 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 5 May 2020 11:07:15 +0000 (13:07 +0200)
According to stateful Codec API the decoder will process all
remaining buffers from before the source change event in
dynamic-resolution-change state and mark the last buffer with
V4L2_BUF_FLAG_LAST.

In Venus case the firmware doesn't mark that last buffer and
some mechanism have to be created in v4l decoder driver.
Fortunately the firmware interface (HFI) claims that the
decoder output buffers will be returned to v4l decoder
driver before it send the insufficient event.

In order to do that we save last queued in the driver capture
buffer in the event_notify and issue flush on output firmware
buffers queue. Once the saved buffer is returned (as a result of
flush command) we mark it as LAST. For all that possible we
extend HFI flush command with one more argument and one more
flush_done HFI driver callback.

Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/qcom/venus/core.h
drivers/media/platform/qcom/venus/hfi.c
drivers/media/platform/qcom/venus/hfi.h
drivers/media/platform/qcom/venus/hfi_msgs.c
drivers/media/platform/qcom/venus/vdec.c

index 3ab644a397863d36b223dffe7b83c9e7b83f4a97..7118612673c97ac245801d3267c779b04c01b00f 100644 (file)
@@ -261,7 +261,8 @@ enum venus_dec_state {
        VENUS_DEC_STATE_SEEK            = 4,
        VENUS_DEC_STATE_DRAIN           = 5,
        VENUS_DEC_STATE_DECODING        = 6,
-       VENUS_DEC_STATE_DRC             = 7
+       VENUS_DEC_STATE_DRC             = 7,
+       VENUS_DEC_STATE_DRC_FLUSH_DONE  = 8,
 };
 
 struct venus_ts_metadata {
@@ -326,6 +327,7 @@ struct venus_ts_metadata {
  * @priv:      a private for HFI operations callbacks
  * @session_type:      the type of the session (decoder or encoder)
  * @hprop:     a union used as a holder by get property
+ * @last_buf:  last capture buffer for dynamic-resoluton-change
  */
 struct venus_inst {
        struct list_head list;
@@ -387,6 +389,7 @@ struct venus_inst {
        union hfi_get_property hprop;
        unsigned int core_acquired: 1;
        unsigned int bit_depth;
+       struct vb2_buffer *last_buf;
 };
 
 #define IS_V1(core)    ((core)->res->hfi_version == HFI_VERSION_1XX)
index 3d8b1284d1f35386b598f2c41deff1fd1e572b98..a211eb93e0f924f6ec22a6eb6b86fdddaa8cd797 100644 (file)
@@ -382,7 +382,7 @@ int hfi_session_unload_res(struct venus_inst *inst)
 }
 EXPORT_SYMBOL_GPL(hfi_session_unload_res);
 
-int hfi_session_flush(struct venus_inst *inst, u32 type)
+int hfi_session_flush(struct venus_inst *inst, u32 type, bool block)
 {
        const struct hfi_ops *ops = inst->core->ops;
        int ret;
@@ -393,9 +393,11 @@ int hfi_session_flush(struct venus_inst *inst, u32 type)
        if (ret)
                return ret;
 
-       ret = wait_session_msg(inst);
-       if (ret)
-               return ret;
+       if (block) {
+               ret = wait_session_msg(inst);
+               if (ret)
+                       return ret;
+       }
 
        return 0;
 }
index 855822c9f39b7923d7e2a56eed408a9353db22f4..62c31529148481791889f5a9497c8c7b7a03ab25 100644 (file)
@@ -102,6 +102,7 @@ struct hfi_inst_ops {
                         u32 hfi_flags, u64 timestamp_us);
        void (*event_notify)(struct venus_inst *inst, u32 event,
                             struct hfi_event_data *data);
+       void (*flush_done)(struct venus_inst *inst);
 };
 
 struct hfi_ops {
@@ -161,7 +162,7 @@ int hfi_session_continue(struct venus_inst *inst);
 int hfi_session_abort(struct venus_inst *inst);
 int hfi_session_load_res(struct venus_inst *inst);
 int hfi_session_unload_res(struct venus_inst *inst);
-int hfi_session_flush(struct venus_inst *inst, u32 type);
+int hfi_session_flush(struct venus_inst *inst, u32 type, bool block);
 int hfi_session_set_buffers(struct venus_inst *inst,
                            struct hfi_buffer_desc *bd);
 int hfi_session_unset_buffers(struct venus_inst *inst,
index 04ef2286efc651a81fa7bc547e1d5d72c9a85923..279a9d6fe737f71ea1d3804fa297064fc0579801 100644 (file)
@@ -439,6 +439,8 @@ static void hfi_session_flush_done(struct venus_core *core,
 
        inst->error = pkt->error_type;
        complete(&inst->done);
+       if (inst->ops->flush_done)
+               inst->ops->flush_done(inst);
 }
 
 static void hfi_session_etb_done(struct venus_core *core,
index f23cbd812ef440f74a180381fdcff4b5929a415a..527944c822b513881b97e575e4ad8fa7a5ed5c73 100644 (file)
@@ -906,7 +906,7 @@ static int vdec_start_capture(struct venus_inst *inst)
                return 0;
 
 reconfigure:
-       ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT);
+       ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true);
        if (ret)
                return ret;
 
@@ -1063,14 +1063,16 @@ static int vdec_stop_capture(struct venus_inst *inst)
 
        switch (inst->codec_state) {
        case VENUS_DEC_STATE_DECODING:
-               ret = hfi_session_flush(inst, HFI_FLUSH_ALL);
+               ret = hfi_session_flush(inst, HFI_FLUSH_ALL, true);
                /* fallthrough */
        case VENUS_DEC_STATE_DRAIN:
                vdec_cancel_dst_buffers(inst);
                inst->codec_state = VENUS_DEC_STATE_STOPPED;
                break;
        case VENUS_DEC_STATE_DRC:
-               ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT);
+               WARN_ON(1);
+               fallthrough;
+       case VENUS_DEC_STATE_DRC_FLUSH_DONE:
                inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP;
                venus_helper_free_dpb_bufs(inst);
                break;
@@ -1091,12 +1093,12 @@ static int vdec_stop_output(struct venus_inst *inst)
        case VENUS_DEC_STATE_DECODING:
        case VENUS_DEC_STATE_DRAIN:
        case VENUS_DEC_STATE_STOPPED:
-               ret = hfi_session_flush(inst, HFI_FLUSH_ALL);
+               ret = hfi_session_flush(inst, HFI_FLUSH_ALL, true);
                inst->codec_state = VENUS_DEC_STATE_SEEK;
                break;
        case VENUS_DEC_STATE_INIT:
        case VENUS_DEC_STATE_CAPTURE_SETUP:
-               ret = hfi_session_flush(inst, HFI_FLUSH_INPUT);
+               ret = hfi_session_flush(inst, HFI_FLUSH_INPUT, true);
                break;
        default:
                break;
@@ -1234,6 +1236,13 @@ static void vdec_buf_done(struct venus_inst *inst, unsigned int buf_type,
                vb->timestamp = timestamp_us * NSEC_PER_USEC;
                vbuf->sequence = inst->sequence_cap++;
 
+               if (inst->last_buf == vb) {
+                       inst->last_buf = NULL;
+                       vbuf->flags |= V4L2_BUF_FLAG_LAST;
+                       vb2_set_plane_payload(vb, 0, 0);
+                       vb->timestamp = 0;
+               }
+
                if (vbuf->flags & V4L2_BUF_FLAG_LAST) {
                        const struct v4l2_event ev = { .type = V4L2_EVENT_EOS };
 
@@ -1311,6 +1320,25 @@ static void vdec_event_change(struct venus_inst *inst,
                }
        }
 
+       /*
+        * The assumption is that the firmware have to return the last buffer
+        * before this event is received in the v4l2 driver. Also the firmware
+        * itself doesn't mark the last decoder output buffer with HFI EOS flag.
+        */
+
+       if (!sufficient && inst->codec_state == VENUS_DEC_STATE_DRC) {
+               struct vb2_v4l2_buffer *last;
+               int ret;
+
+               last = v4l2_m2m_last_dst_buf(inst->m2m_ctx);
+               if (last)
+                       inst->last_buf = &last->vb2_buf;
+
+               ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false);
+               if (ret)
+                       dev_dbg(dev, "flush output error %d\n", ret);
+       }
+
        inst->reconfig = true;
        v4l2_event_queue_fh(&inst->fh, &ev);
        wake_up(&inst->reconf_wait);
@@ -1351,9 +1379,16 @@ static void vdec_event_notify(struct venus_inst *inst, u32 event,
        }
 }
 
+static void vdec_flush_done(struct venus_inst *inst)
+{
+       if (inst->codec_state == VENUS_DEC_STATE_DRC)
+               inst->codec_state = VENUS_DEC_STATE_DRC_FLUSH_DONE;
+}
+
 static const struct hfi_inst_ops vdec_hfi_ops = {
        .buf_done = vdec_buf_done,
        .event_notify = vdec_event_notify,
+       .flush_done = vdec_flush_done,
 };
 
 static void vdec_inst_init(struct venus_inst *inst)