From patchwork Mon Aug 16 04:31:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13366 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 1270AC3241 for ; Mon, 16 Aug 2021 04:32:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFC13688A2; Mon, 16 Aug 2021 06:32:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ai1Ghl5X"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6DA5D6888A for ; Mon, 16 Aug 2021 06:32:00 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id u21-20020a17090a8915b02901782c36f543so30382725pjn.4 for ; Sun, 15 Aug 2021 21:32:00 -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=FsWpdqKw6TMEtZZ057bMVlcaK+oi5l0g77pu+9nPVwU=; b=Ai1Ghl5XvjCssy3QWXHJOeWM06Eas8kttZenRR+pYIoEjr9JRfsZbB7IM0OzNcRCMz xpg94cTxkyaFWUqthxVR9w6q9UB19LKRGstFZdKFGDrPAG9DlU6ghGDVSjaIbMdK3cM6 PeNOIsaMPjn3FIL9wwkCqF7dIRDYBK8rLeYRQ= 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=FsWpdqKw6TMEtZZ057bMVlcaK+oi5l0g77pu+9nPVwU=; b=cNDVOByA/utEBEhXUUQf9NeKs05m/+lskFQyxLbBqbu1t50LLDCjrzWFGEp973hlNy DUwxA0XknN50y29tNMSTL4dQNajemWwKTSIpEU3GTAEc+SMRCwJBltwThAyO8y4Z7oHi 0rK1U499wsxS0GHtSqTTcTMNZFx6rc+lqi42k9XuGfOH0SpnT4q2QIDpmdGHmvCyI+qs 9S3vtxND7hC1nd8Ku6szIXqOEbGOeSmUckQ5F5BwIipiWHRgGgqDEbxsvR7pAkX+dxee V54l3ISgRMmGeiA6ov73JQv5rvJVZNHTENtDvaxk2V+Kgt+KaUDC2qVmllnl7PzSXFPS kZuw== X-Gm-Message-State: AOAM53099oIOgri0HGEShJPAVwELFjaS9If9skW/Xr65LgmROnFa/w6l 9KxQP+RmLd0FhsGU7ypFaIuSoPLb0gx3fQ== X-Google-Smtp-Source: ABdhPJx1c/GOOfJm7hI5owshTMQpqTBNXpoTZ49tcfzYTJBURoM8VRt9fb+FpTIr+wzYv+800wJ9eg== X-Received: by 2002:a17:902:b095:b029:12c:de88:7d3b with SMTP id p21-20020a170902b095b029012cde887d3bmr11629356plr.15.1629088318684; Sun, 15 Aug 2021 21:31:58 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:58 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:36 +0900 Message-Id: <20210816043138.957984-9-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 08/10] libcamera: v4l2_videodevice: Create color-format planes in CreateBuffer() 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" V4L2VideDevice::CreateBuffer() creates the same number of FrameBuffer::Planes as V4L2 format planes. Therefore, if the v4l2 format single is single-planar format, the created number of FrameBuffer::Planes is 1. It should rather create the same number of FrameBuffer::Planes as the color format planes. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_videodevice.h | 4 ++- src/libcamera/v4l2_videodevice.cpp | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index e767ec84..d0aeb614 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -136,11 +136,13 @@ private: private: struct Plane { Plane(const FrameBuffer::Plane &plane) - : fd(plane.fd.fd()), length(plane.length) + : fd(plane.fd.fd()), offset(plane.offset), + length(plane.length) { } int fd; + unsigned int offset; unsigned int length; }; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ce60dff6..549418c8 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -25,6 +25,7 @@ #include +#include "libcamera/internal/formats.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/media_object.h" @@ -273,6 +274,7 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const for (unsigned int i = 0; i < planes.size(); i++) if (planes_[i].fd != planes[i].fd.fd() || + planes_[i].offset != planes_[i].offset || planes_[i].length != planes[i].length) return false; return true; @@ -1283,12 +1285,34 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) FrameBuffer::Plane plane; plane.fd = std::move(fd); - plane.length = multiPlanar ? - buf.m.planes[nplane].length : buf.length; + plane.offset = multiPlanar ? buf.m.planes[nplane].data_offset : 0; + plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; planes.push_back(std::move(plane)); } + V4L2DeviceFormat format{}; + ret = getFormat(&format); + if (ret < 0) { + LOG(V4L2, Error) + << "Failed to get format: " << strerror(-ret); + return nullptr; + } + + const auto &info = PixelFormatInfo::info(format.fourcc); + if (info.isValid() && info.numPlanes() != numPlanes) { + ASSERT(numPlanes == 1u); + planes.resize(info.numPlanes()); + const FileDescriptor &fd = planes[0].fd; + size_t offset = 0; + for (size_t i = 0; i < info.numPlanes(); ++i) { + planes[i].fd = fd; + planes[i].offset = offset; + planes[i].length = info.frameSize(format.size); + offset += planes[i].length; + } + } + return std::make_unique(std::move(planes)); }