Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2042607pxu; Fri, 9 Oct 2020 06:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmjwuirYF/w/Prmf/0WaY78NVs7/Hp+xqn/4Mn0utQSjWjQ+dgIzH63tOkOXbnVsqrfVud X-Received: by 2002:a17:906:268d:: with SMTP id t13mr14346010ejc.60.1602250561001; Fri, 09 Oct 2020 06:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602250560; cv=none; d=google.com; s=arc-20160816; b=t8vwmyocyZCzh1CpBHqq2aa02eTg+nakmRQQCDj4SbsjoxuKDt4k+kg/V8n5Mnq1zL xQ7NTD1Q/UozO+8L3utn8amCyKGgJ2JDIPacWwzB/TPuA2+Sia4Yd0Xbx88oZayaCrST ay4zBd1B8gLPcY+UG5UgSgCpjQACxvkrbe6zaS6nrLqKjG6VhnqfQjnrdN/8V+8OUg1X bWi6CE85M8095TlWw37TGpmD3zGwAhRHz/AjTAo63SY8Z86vVPm9Jz58kG0svCDBcb/V B4SmMHGgmBbNS2/ncHiqbQGC7e0PWGMT3Gm/cvxHsX5PhwJ2re6+CUM7y2ZkQyDAa/5W IfPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R6eMuYXKQBt8ZcD3TVM9l7/XPveGAmfJeT8PkVlMs9k=; b=HfUET1l+7I90OaFtKq0dZRxYNW+KKWJs9zgbRjBXHuPeF2FaOqIHcEAH57IWIW/4mQ TEz0DWifY1sq9dGZHNwmbRvg2R3KPbcqRaz17ENdAfCpG5AVRIlhIH8dheSnmv1nEDUg LgYgkGfMYUCpedN83gBHh0ouuGy21T/98A4U2QZsyJXQiCkPHrC6Kqm0nGLvXCYZrKW5 95hhDjANlXBbCzqoz+BqbS4nzkmo0DNozkgAj1BBUh8CPe2uE+tFFSIDutoxjVJy3Izx ios+qdHRKWo6+Y+uQkYyt6CYzPqC9VXVE/rJm8Ue/MPrOsTVuWA+H+ErCtEOMUuDnSuN /uUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="T0Vu1G/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si7224186ejv.268.2020.10.09.06.35.36; Fri, 09 Oct 2020 06:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="T0Vu1G/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732290AbgJIMpp (ORCPT + 99 others); Fri, 9 Oct 2020 08:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732022AbgJIMpo (ORCPT ); Fri, 9 Oct 2020 08:45:44 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA286C0613D6 for ; Fri, 9 Oct 2020 05:45:42 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id 16so10023399oix.9 for ; Fri, 09 Oct 2020 05:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R6eMuYXKQBt8ZcD3TVM9l7/XPveGAmfJeT8PkVlMs9k=; b=T0Vu1G/Ug2wRJI0vRjA5g0OvhN2VRMMML12ko89+m0vbUSpLlg5KfV49Ph9urGJKCd c69qKYqhH0IWar44sqdiakV75IeEQIvgl+S9z6trLyIukc/KgwDcr6LChy55JCsAeLtF mbTtzjwq4dnzqXQSMgyhctpsWK4v0bt4zKZPM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R6eMuYXKQBt8ZcD3TVM9l7/XPveGAmfJeT8PkVlMs9k=; b=M8uMHuGy28xuzvlbyvE9SUQ0uQopVo4niogD1S4ndHNfN+R8a4Am+2M6aAgKWPj+eX 2+8NtnMOwV7DsIIJJFdTfNTeAsQDq/LKCJDuT9e1xhmStAShqLVQ6yg5QT9D4rF+VPj3 xbYCwJuCTVsRTs5jVQscRzbNGBlxyKKiXn5Uz+prHPW5o44vLspOrkf7LVVVFb1kzCFp r/OHFWLuCv8qmD/P9M/xhPEmEAfv7p5pMrEhLWww0Zd253yLDPDOk37BLANSI2aioOLt 388KmWRjZrf6cNHSqpITmj7UUDnjxKfOeA3R82tsUelQ5pqOmUEAOX4YqHZdFVeNDpd9 ZaMA== X-Gm-Message-State: AOAM530ttuJxpqhSmC0MCUYTVsG/pkiswwkrhgc9+LYCpxeOaw1NZn/0 IxmSb0s4lFpxy+kgYAnhzjz+V+wNz52jurip X-Received: by 2002:aca:b2d7:: with SMTP id b206mr2405470oif.110.1602247541388; Fri, 09 Oct 2020 05:45:41 -0700 (PDT) Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com. [209.85.210.45]) by smtp.gmail.com with ESMTPSA id i12sm2181343oto.34.2020.10.09.05.45.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Oct 2020 05:45:40 -0700 (PDT) Received: by mail-ot1-f45.google.com with SMTP id q21so8840080ota.8 for ; Fri, 09 Oct 2020 05:45:40 -0700 (PDT) X-Received: by 2002:a9d:6445:: with SMTP id m5mr8454412otl.36.1602247539630; Fri, 09 Oct 2020 05:45:39 -0700 (PDT) MIME-Version: 1.0 References: <20200928164431.21884-1-stanimir.varbanov@linaro.org> <20200928164431.21884-2-stanimir.varbanov@linaro.org> In-Reply-To: <20200928164431.21884-2-stanimir.varbanov@linaro.org> From: Alexandre Courbot Date: Fri, 9 Oct 2020 21:45:27 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] venus: vdec: Fix non reliable setting of LAST flag To: Stanimir Varbanov Cc: Linux Media Mailing List , linux-arm-msm@vger.kernel.org, LKML , Vikash Garodia , Mansur Alisha Shaik Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 1:44 AM Stanimir Varbanov wrote: > > In real use of dynamic-resolution-change it is observed that the > LAST buffer flag (which marks the last decoded buffer with the > resolution before the resolution-change event) is not reliably set. > > Fix this by set the LAST buffer flag on next queued capture buffer > after the resolution-change event. > > Signed-off-by: Stanimir Varbanov > --- > drivers/media/platform/qcom/venus/core.h | 5 +- > drivers/media/platform/qcom/venus/helpers.c | 6 +++ > drivers/media/platform/qcom/venus/vdec.c | 52 ++++++++++++--------- > 3 files changed, 38 insertions(+), 25 deletions(-) > > diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h > index 7b79a33dc9d6..e30eeaf0ada9 100644 > --- a/drivers/media/platform/qcom/venus/core.h > +++ b/drivers/media/platform/qcom/venus/core.h > @@ -274,7 +274,6 @@ enum venus_dec_state { > VENUS_DEC_STATE_DRAIN = 5, > VENUS_DEC_STATE_DECODING = 6, > VENUS_DEC_STATE_DRC = 7, > - VENUS_DEC_STATE_DRC_FLUSH_DONE = 8, > }; > > struct venus_ts_metadata { > @@ -339,7 +338,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 > + * @next_buf_last: a flag to mark next queued capture buffer as last > */ > struct venus_inst { > struct list_head list; > @@ -401,7 +400,7 @@ struct venus_inst { > union hfi_get_property hprop; > unsigned int core_acquired: 1; > unsigned int bit_depth; > - struct vb2_buffer *last_buf; > + bool next_buf_last; > }; > > #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX) > diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c > index 50439eb1ffea..5ca3920237c5 100644 > --- a/drivers/media/platform/qcom/venus/helpers.c > +++ b/drivers/media/platform/qcom/venus/helpers.c > @@ -1347,6 +1347,12 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb) > > v4l2_m2m_buf_queue(m2m_ctx, vbuf); > > + /* Skip processing queued capture buffers after LAST flag */ > + if (inst->session_type == VIDC_SESSION_TYPE_DEC && > + V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) && > + inst->codec_state == VENUS_DEC_STATE_DRC) > + goto unlock; > + > cache_payload(inst, vb); > > if (inst->session_type == VIDC_SESSION_TYPE_ENC && > diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c > index ea13170a6a2c..c11bdf3ca21b 100644 > --- a/drivers/media/platform/qcom/venus/vdec.c > +++ b/drivers/media/platform/qcom/venus/vdec.c > @@ -914,10 +914,6 @@ static int vdec_start_capture(struct venus_inst *inst) > return 0; > > reconfigure: > - ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true); > - if (ret) > - return ret; > - > ret = vdec_output_conf(inst); > if (ret) > return ret; > @@ -954,6 +950,7 @@ static int vdec_start_capture(struct venus_inst *inst) > inst->streamon_cap = 1; > inst->sequence_cap = 0; > inst->reconfig = false; > + inst->next_buf_last = false; Is this needed? Whether a resolution change occurs should only be dependent on what the OUTPUT queue receives, so even if the CAPTURE queue is stopped and resumed for some reason, pending resolution change events and their associated LAST buffer should still be emitted. With this statement we are taking the risk of sending a change resolution event without a corresponding LAST buffer (so the following LAST buffer might be misinterpreted). > > return 0; > > @@ -985,6 +982,7 @@ static int vdec_start_output(struct venus_inst *inst) > venus_helper_init_instance(inst); > inst->sequence_out = 0; > inst->reconfig = false; > + inst->next_buf_last = false; This one I understand better - if the client seeks, it should probably check for pending events before resuming. > > ret = vdec_set_properties(inst); > if (ret) > @@ -1078,9 +1076,7 @@ static int vdec_stop_capture(struct venus_inst *inst) > inst->codec_state = VENUS_DEC_STATE_STOPPED; > break; > case VENUS_DEC_STATE_DRC: > - WARN_ON(1); > - fallthrough; > - case VENUS_DEC_STATE_DRC_FLUSH_DONE: > + ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true); > inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP; > venus_helper_free_dpb_bufs(inst); > break; > @@ -1204,9 +1200,28 @@ static void vdec_buf_cleanup(struct vb2_buffer *vb) > static void vdec_vb2_buf_queue(struct vb2_buffer *vb) > { > struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); > + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); > + static const struct v4l2_event eos = { .type = V4L2_EVENT_EOS }; > > vdec_pm_get_put(inst); > > + mutex_lock(&inst->lock); > + > + if (inst->next_buf_last && V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) && > + inst->codec_state == VENUS_DEC_STATE_DRC) { > + vbuf->flags |= V4L2_BUF_FLAG_LAST; > + vbuf->sequence = inst->sequence_cap++; > + vbuf->field = V4L2_FIELD_NONE; > + vb2_set_plane_payload(vb, 0, 0); > + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE); > + v4l2_event_queue_fh(&inst->fh, &eos); I don't think publishing an EOS event here is correct. As the spec says: " ... Last of the buffers will have the V4L2_BUF_FLAG_LAST flag set. To determine the sequence to follow, the client must check if there is any pending event and: * if a V4L2_EVENT_SOURCE_CHANGE event with changes set to V4L2_EVENT_SRC_CH_RESOLUTION is pending, the Dynamic Resolution Change sequence needs to be followed, * if a V4L2_EVENT_EOS event is pending, the End of Stream sequence needs to be followed. " With this we will have *both* resolution change and EOS events pending when the client checks the event queue after receiving the LAST buffer. > + inst->next_buf_last = false; > + mutex_unlock(&inst->lock); > + return; > + } > + > + mutex_unlock(&inst->lock); > + > venus_helper_vb2_buf_queue(vb); > } > > @@ -1250,13 +1265,6 @@ 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 }; > > @@ -1344,13 +1352,14 @@ static void vdec_event_change(struct venus_inst *inst, > struct vb2_v4l2_buffer *last; > int ret; > > - last = v4l2_m2m_last_dst_buf(inst->m2m_ctx); > - if (last) > - inst->last_buf = &last->vb2_buf; > + inst->next_buf_last = true; > > - ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false); > - if (ret) > - dev_dbg(dev, VDBGH "flush output error %d\n", ret); > + last = v4l2_m2m_last_dst_buf(inst->m2m_ctx); > + if (last) { > + ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false); > + if (ret) > + dev_dbg(dev, VDBGH "flush output error %d\n", ret); > + } > } > > inst->reconfig = true; > @@ -1395,8 +1404,7 @@ 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; > + dev_dbg(inst->core->dev_dec, VDBGH "flush done\n"); > } > > static const struct hfi_inst_ops vdec_hfi_ops = { > -- > 2.17.1 >