From patchwork Wed Oct 9 09:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21560 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 080FAC32DE for ; Wed, 9 Oct 2024 09:33:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AADCA6353B; Wed, 9 Oct 2024 11:33:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cpsOxVsr"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 476FA6536C for ; Wed, 9 Oct 2024 11:33:14 +0200 (CEST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20c544d345cso5468005ad.1 for ; Wed, 09 Oct 2024 02:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728466392; x=1729071192; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VmCu62yS5Rb1RA+QKSraMXKAV3NXX4xRRST9jf3Qxkg=; b=cpsOxVsrpOitJQnZowp0uoTrTPwbLyweC2ZBnRjX/JRSdo4O4Olh09h2ENSERaKwSp Ljqh1cG3yFzqBljxwMSgqH2QucpdYevbtMC0EDHlMUk36Shd6cYmmDIfpIayyrlhpAks x7uLHvJm8x0sPP2Z6l3U8hdbKxxai9Ikr+PSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728466392; x=1729071192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VmCu62yS5Rb1RA+QKSraMXKAV3NXX4xRRST9jf3Qxkg=; b=ve/JbQbc/0nN3Vp8gPLDqdh0xLOhA1Jzl6mwRD1FxdheoBqJckfYJU1Judab4W2I4+ ACo9AKw/9/dM2qRZMFxFW6pQtm73lTSNGrS5LWtST1Sz4FW43Pg3uFMu5x9Guyxhx2u8 WUT0tQAXB7Z7dDPFK6umacZcBOIH0A51PwuNhyFdeL62OmIELRlUIHcA0sbcq7gyaALY wR5A8S7V0ucu2nSzvDJOjvRXkeJID84sT6el/bmh+m9DHEKRv2YUdpHWfgZHBjwcZGvB eQvaKr8RaE8HxDxeaDOGvPRvNLhyZbUJQl5E5M4VxvghLg2c4PXjEUj9neO7Dfawuv6z Airw== X-Gm-Message-State: AOJu0YxsdjSCR6ERFM6J1NWui3mzskRTBiNt/uXkxQj6QDOarcWWYoYQ Q2maYYk2WLfg25IjQuzEqhPZah/fDgonKpNGEhZxnWT/Yc0G5snPtC5p1x4EhF15LGXsAQDQjYA = X-Google-Smtp-Source: AGHT+IGnkPRhugvQWAC6Guzw4wz9LmTlY6qSqWXuRhCiwXndJHfUBmBvVLfaKuRJFL364+Wo0mC5vA== X-Received: by 2002:a17:902:e749:b0:20b:5aeb:9b8 with SMTP id d9443c01a7336-20c6352ed90mr32185005ad.24.1728466392080; Wed, 09 Oct 2024 02:33:12 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c13939b27sm67313145ad.136.2024.10.09.02.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 02:33:11 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yunke Cao , Han-Lin Chen , Harvey Yang Subject: [PATCH 1/1] libcamera: mtkisp7: v4l2: Add a requestBufferReady signal Date: Wed, 9 Oct 2024 09:26:39 +0000 Message-ID: <20241009093303.2996819-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog In-Reply-To: <20241009093303.2996819-1-chenghaoyang@chromium.org> References: <20241009093303.2996819-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Yunke Cao We will be adding a large number buffers for a single media request. Matching each single FrameBuffer against all the buffers will be an unnecessary huge effort. Add a new signal that emits both the frameBuffer and the mediaRequest, match the mediaRequest instead in IMGSYS. Signed-off-by: Han-Lin Chen Co-developed-by: Yunke Cao Signed-off-by: Yunke Cao Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- include/libcamera/internal/v4l2_videodevice.h | 3 +- src/libcamera/v4l2_videodevice.cpp | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index f021c2a01..c44e9e9c7 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -220,6 +220,7 @@ public: int queueBuffer(FrameBuffer *buffer); Signal bufferReady; + Signal> requestBufferReady; int streamOn(); int streamOff(); @@ -265,7 +266,7 @@ private: UniqueFD exportDmabufFd(unsigned int index, unsigned int plane); void bufferAvailable(); - FrameBuffer *dequeueBuffer(); + std::pair dequeueBuffer(); void watchdogExpired(); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 14eba0561..5a1648602 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1773,18 +1773,23 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) * * When this slot is called, a Buffer has become available from the device, and * will be emitted through the bufferReady Signal. + * If the buffer is queued with a media Request, emit a requestBufferReady + * signal. * * For Capture video devices the FrameBuffer will contain valid data. * For Output video devices the FrameBuffer can be considered empty. */ void V4L2VideoDevice::bufferAvailable() { - FrameBuffer *buffer = dequeueBuffer(); + auto [buffer, mediaRequest] = dequeueBuffer(); if (!buffer) return; /* Notify anyone listening to the device. */ bufferReady.emit(buffer); + + if (mediaRequest > 0) + requestBufferReady.emit({ buffer, mediaRequest }); } /** @@ -1793,9 +1798,12 @@ void V4L2VideoDevice::bufferAvailable() * This function dequeues the next available buffer from the device. If no * buffer is available to be dequeued it will return nullptr immediately. * - * \return A pointer to the dequeued buffer on success, or nullptr otherwise + * \return A pair where the first element is a pointer to the dequeued buffer + * on success, or nullptr otherwise. The second is the media request fd if + * applicable + * */ -FrameBuffer *V4L2VideoDevice::dequeueBuffer() +std::pair V4L2VideoDevice::dequeueBuffer() { struct v4l2_buffer buf = {}; struct v4l2_plane planes[VIDEO_MAX_PLANES] = {}; @@ -1815,7 +1823,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() if (ret < 0) { LOG(V4L2, Error) << "Failed to dequeue buffer: " << strerror(-ret); - return nullptr; + return { nullptr, -1 }; } LOG(V4L2, Debug) << "Dequeuing buffer " << buf.index; @@ -1837,7 +1845,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() LOG(V4L2, Error) << "Dequeued unexpected buffer index " << buf.index; - return nullptr; + return { nullptr, -1 }; } cache_->put(buf.index); @@ -1866,7 +1874,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() + buf.timestamp.tv_usec * 1000ULL; if (V4L2_TYPE_IS_OUTPUT(buf.type)) - return buffer; + return { buffer, buf.request_fd }; /* * Detect kernel drivers which do not reset the sequence number to zero @@ -1896,7 +1904,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() << " != " << buffer->planes().size() << ")"; metadata.status = FrameMetadata::FrameError; - return buffer; + return { buffer, buf.request_fd }; } /* @@ -1921,7 +1929,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() }); metadata.status = FrameMetadata::FrameError; - return buffer; + return { buffer, buf.request_fd }; } metadata.planes()[i].bytesused = @@ -1940,7 +1948,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() metadata.planes()[0].bytesused = buf.bytesused; } - return buffer; + return { buffer, buf.request_fd }; } /** @@ -1948,6 +1956,12 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() * \brief A Signal emitted when a framebuffer completes */ +/** + * \var V4L2VideoDevice::requestBufferReady + * \brief A Signal emitted when a framebuffer completes, which includes both the + * frameBuffer and the media request fd. + */ + /** * \brief Start the video stream * \return 0 on success or a negative error code otherwise @@ -2012,6 +2026,7 @@ int V4L2VideoDevice::streamOff() cache_->put(it.first); metadata.status = FrameMetadata::FrameCancelled; bufferReady.emit(buffer); + requestBufferReady.emit({ buffer, -1 }); } ASSERT(cache_->isEmpty());