Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3526861pxv; Sun, 4 Jul 2021 22:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyxiVKkZz1ZqHJsbbS1tXPW+Gfh0jx9DUsptrmEjiaHpe50VAAfIhXMfGVrCUUniS03HGJ X-Received: by 2002:aa7:dd43:: with SMTP id o3mr14098653edw.302.1625463305265; Sun, 04 Jul 2021 22:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625463305; cv=none; d=google.com; s=arc-20160816; b=NmsKtX8TGyFxF0SeBYRGNNv6zhDA4lULcN1Oz+X3Wf9D+Vf6rkcTHbG8dEXRzI7tsC yRRGHMM2vYwkqLvwEm+J8woDsAf8lczx4BzIqBNc0ixt/m/pq9pkt3eK4WzywUfLwf9l bXHqJots0Ky9/WF79qzkyA67H+4qPoJcAXYvSJch1w0gFJutBSapKEYCoAi0dwx5k5vB v5vh4gHBuAkI8ssmr5p6iLRpsaMxQXKf0c9W9QtswnFfuIUlsk0iZwPzBvjlNBMarYsD ZKFF1jmFZVY88rtoyaCSCQXnSGJOQSt/0eue5MDq9UYapJQ6+E+3mhxT5fi3P+M0nri1 vkxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8/iq39xanR+np3JTP99hzwqOOEzqUU4t0BZOBeMWeOw=; b=y/UI+xFRa2WXzuFtjczPbdNsM4W7j8pb7OFslD333tl94zOx2YT9yKCjnphNL5l00V CvLAmC4IGpDq1/1QpBI6a+nVkbHvTbVmvrMej/J7KepiRu6JxSWkI3IlSsIbicwzy0Sh GRbS01THi7LxgaBioPXgidJhGQk98aEtgdb99hx4+zbXYqYvnZD7xa62c/LB07tKUZNz Z831pstksVsK6+dsOJsksmIFO5sLzP2zuWbKaEKMsMmkv2IJ4lLdXTLwR3Pf7yrPMPJ4 gQLcjNHlSTxFWWZ+99HzgU8YXmwGx1d/ARoRwMuKu06kVhxx7XFsqcYP18icpbYICcju VWxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JCWYfvZz; 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 hv20si802403ejc.521.2021.07.04.22.34.41; Sun, 04 Jul 2021 22:35:05 -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=JCWYfvZz; 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 S229931AbhGEFgP (ORCPT + 99 others); Mon, 5 Jul 2021 01:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbhGEFgI (ORCPT ); Mon, 5 Jul 2021 01:36:08 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BBE9C061762 for ; Sun, 4 Jul 2021 22:33:32 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id o18so16615719pgu.10 for ; Sun, 04 Jul 2021 22:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8/iq39xanR+np3JTP99hzwqOOEzqUU4t0BZOBeMWeOw=; b=JCWYfvZzwyAf3mGBsLtlYle5K8IIYcAhPGlqnxi2codcXVEqqBBSk4VlKP1TxkYegr 1CLwjznDYH9lNod8yMCh1ByhT+bI2ILyym2r0UItEFNKAs0ajdufmjfmCoHqlDpWKJpd Mz3hkOuiQLOBB1Mj59FQCOdkOwHSnvOwq/cXk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8/iq39xanR+np3JTP99hzwqOOEzqUU4t0BZOBeMWeOw=; b=L68gRtw0VcJhkq2fjvCUAwKscU+HOKCwb5zrZ+vvtFtBmhWsztJV5sV7hHQ50a/PxI eXF8uCaVk0BWnwpBIsYBLKIF90GhZHkwsAcqfqY5XUriUFatgJS4wk4lBR2WxJkxkBS1 Ac5T2vScXaduQHejIEdGf7Tpz22PpC2Os/I6Kp1WzgDIkNWTmqV5YGw90Bclht4Ugi3e YRQOoVoySrukgji0aTrlBmWAEfX0mvCf0VoVfM9xf0QIUHe66/WMOg3E+oba7KuttZcu aEmC74vQLyi6vEf/cwl/JnW/Z8uF0Pa96wU/XrApkuD1R70Q0NkfgVvOf99YUnA0aShK kKKg== X-Gm-Message-State: AOAM531D1eASAN1TybxzynhoX4l2XBJFS9owX1rR/2kmMXaRcGRFoZST zIode+RNoP2BoCtBK5S9ftaaSg== X-Received: by 2002:a62:e111:0:b029:31b:8150:38b4 with SMTP id q17-20020a62e1110000b029031b815038b4mr8532393pfh.48.1625463211999; Sun, 04 Jul 2021 22:33:31 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:3fed:7130:60f:265a]) by smtp.gmail.com with ESMTPSA id x19sm6805245pfp.115.2021.07.04.22.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 22:33:31 -0700 (PDT) From: Alexandre Courbot To: Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Dafna Hirschfeld , Yunfei Dong Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Alexandre Courbot , Tzung-Bi Shih Subject: [PATCH v6 04/14] media: mtk-vcodec: make flush buffer reusable by encoder Date: Mon, 5 Jul 2021 14:32:48 +0900 Message-Id: <20210705053258.1614177-5-acourbot@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210705053258.1614177-1-acourbot@chromium.org> References: <20210705053258.1614177-1-acourbot@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The flush buffer is a special buffer that tells the decoder driver to send an empty CAPTURE frame to the client with V4L2_BUF_FLAG_LAST set. We need similar functionality for the encoder ; however currently the flush buffer depends on decoder-specific structures and thus cannot be reused with the encoder. Fix this by testing for this buffer by its VB2 address, and not through a dedicated flag stored in a higher-level decoder structure. This also allows us to remove said flag and simplify the code a bit. Since the flush buffer should never be used in the stateless decoder, also add safeguards to check against it. Signed-off-by: Alexandre Courbot Reviewed-by: Tzung-Bi Shih --- .../platform/mtk-vcodec/mtk_vcodec_dec.c | 24 +++++++++---------- .../platform/mtk-vcodec/mtk_vcodec_dec.h | 2 -- .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 12 +--------- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 6 +++-- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c index 16e057f73789..7edd6266dc6a 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c @@ -368,8 +368,6 @@ static void mtk_vdec_worker(struct work_struct *work) return; } - src_buf_info = container_of(src_buf, struct mtk_video_dec_buf, - m2m_buf.vb); dst_buf_info = container_of(dst_buf, struct mtk_video_dec_buf, m2m_buf.vb); @@ -390,7 +388,7 @@ static void mtk_vdec_worker(struct work_struct *work) pfb->base_y.va, &pfb->base_y.dma_addr, &pfb->base_c.dma_addr, pfb->base_y.size); - if (src_buf_info->lastframe) { + if (src_buf == &ctx->empty_flush_buf.vb) { mtk_v4l2_debug(1, "Got empty flush input buffer."); src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); @@ -411,6 +409,10 @@ static void mtk_vdec_worker(struct work_struct *work) v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); return; } + + src_buf_info = container_of(src_buf, struct mtk_video_dec_buf, + m2m_buf.vb); + buf.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0); buf.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0); buf.size = (size_t)src_buf->vb2_buf.planes[0].bytesused; @@ -514,8 +516,7 @@ static int vidioc_decoder_cmd(struct file *file, void *priv, mtk_v4l2_debug(1, "Capture stream is off. No need to flush."); return 0; } - v4l2_m2m_buf_queue(ctx->m2m_ctx, - &ctx->empty_flush_buf->m2m_buf.vb); + v4l2_m2m_buf_queue(ctx->m2m_ctx, &ctx->empty_flush_buf.vb); v4l2_m2m_try_schedule(ctx->m2m_ctx); break; @@ -1122,7 +1123,6 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb) unsigned int dpbsize = 1, i = 0; struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); struct vb2_v4l2_buffer *vb2_v4l2 = NULL; - struct mtk_video_dec_buf *buf = NULL; struct mtk_q_data *dst_q_data; mtk_v4l2_debug(3, "[%d] (%d) id=%d, vb=%p", @@ -1132,6 +1132,8 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb) * check if this buffer is ready to be used after decode */ if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + struct mtk_video_dec_buf *buf; + vb2_v4l2 = to_vb2_v4l2_buffer(vb); buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb); @@ -1161,8 +1163,8 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb) mtk_v4l2_err("No src buffer"); return; } - buf = container_of(src_buf, struct mtk_video_dec_buf, m2m_buf.vb); - if (buf->lastframe) { + + if (src_buf == &ctx->empty_flush_buf.vb) { /* This shouldn't happen. Just in case. */ mtk_v4l2_err("Invalid flush buffer."); v4l2_m2m_src_buf_remove(ctx->m2m_ctx); @@ -1267,8 +1269,6 @@ static int vb2ops_vdec_buf_init(struct vb2_buffer *vb) if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { buf->used = false; buf->queued_in_v4l2 = false; - } else { - buf->lastframe = false; } return 0; @@ -1294,9 +1294,7 @@ static void vb2ops_vdec_stop_streaming(struct vb2_queue *q) if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { while ((src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) { - struct mtk_video_dec_buf *buf_info = container_of( - src_buf, struct mtk_video_dec_buf, m2m_buf.vb); - if (!buf_info->lastframe) + if (src_buf != &ctx->empty_flush_buf.vb) v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); } diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h index cf26b6c1486a..1f8b7300dce6 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h @@ -40,7 +40,6 @@ struct vdec_fb { * @queued_in_vb2: Capture buffer is queue in vb2 * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2 * queue yet - * @lastframe: Intput buffer is last buffer - EOS * @error: An unrecoverable error occurs on this buffer. * @frame_buffer: Decode status, and buffer information of Capture buffer * @@ -52,7 +51,6 @@ struct mtk_video_dec_buf { bool used; bool queued_in_vb2; bool queued_in_v4l2; - bool lastframe; bool error; struct vdec_fb frame_buffer; }; diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c index f87dc47d9e63..5ce7f1b83e4e 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -81,21 +81,14 @@ static int fops_vcodec_open(struct file *file) { struct mtk_vcodec_dev *dev = video_drvdata(file); struct mtk_vcodec_ctx *ctx = NULL; - struct mtk_video_dec_buf *mtk_buf = NULL; int ret = 0; struct vb2_queue *src_vq; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; - mtk_buf = kzalloc(sizeof(*mtk_buf), GFP_KERNEL); - if (!mtk_buf) { - kfree(ctx); - return -ENOMEM; - } mutex_lock(&dev->dev_mutex); - ctx->empty_flush_buf = mtk_buf; ctx->id = dev->id_counter++; v4l2_fh_init(&ctx->fh, video_devdata(file)); file->private_data = &ctx->fh; @@ -121,8 +114,7 @@ static int fops_vcodec_open(struct file *file) } src_vq = v4l2_m2m_get_vq(ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); - ctx->empty_flush_buf->m2m_buf.vb.vb2_buf.vb2_queue = src_vq; - ctx->empty_flush_buf->lastframe = true; + ctx->empty_flush_buf.vb.vb2_buf.vb2_queue = src_vq; mtk_vcodec_dec_set_default_params(ctx); if (v4l2_fh_is_singular(&ctx->fh)) { @@ -162,7 +154,6 @@ static int fops_vcodec_open(struct file *file) err_ctrls_setup: v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); - kfree(ctx->empty_flush_buf); kfree(ctx); mutex_unlock(&dev->dev_mutex); @@ -193,7 +184,6 @@ static int fops_vcodec_release(struct file *file) v4l2_ctrl_handler_free(&ctx->ctrl_hdl); list_del_init(&ctx->list); - kfree(ctx->empty_flush_buf); kfree(ctx); mutex_unlock(&dev->dev_mutex); return 0; diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h index c6c7672fecfb..cad52d8b1463 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "mtk_vcodec_util.h" @@ -249,7 +250,8 @@ struct vdec_pic_info { * @decode_work: worker for the decoding * @encode_work: worker for the encoding * @last_decoded_picinfo: pic information get from latest decode - * @empty_flush_buf: a fake size-0 capture buffer that indicates flush + * @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Only + * to be used with encoder and stateful decoder. * * @colorspace: enum v4l2_colorspace; supplemental to pixelformat * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding @@ -288,7 +290,7 @@ struct mtk_vcodec_ctx { struct work_struct decode_work; struct work_struct encode_work; struct vdec_pic_info last_decoded_picinfo; - struct mtk_video_dec_buf *empty_flush_buf; + struct v4l2_m2m_buffer empty_flush_buf; enum v4l2_colorspace colorspace; enum v4l2_ycbcr_encoding ycbcr_enc; -- 2.32.0.93.g670b81a890-goog