From patchwork Mon Aug 23 13:12:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13452 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 456ECBD87C for ; Mon, 23 Aug 2021 13:12:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C767688D2; Mon, 23 Aug 2021 15:12:55 +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="EZqGupbA"; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 821C86890E for ; Mon, 23 Aug 2021 15:12:53 +0200 (CEST) Received: by mail-pl1-x632.google.com with SMTP id x15so696955plg.10 for ; Mon, 23 Aug 2021 06:12:53 -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=/9J16zTMj+xkiz3SwiR2BYYmrKOcbO95+Sg/9KpSF18=; b=EZqGupbASLja44QyjTyBDa4ro8KFc/eJsUMAF66IIe6Dbc36lKecpHu9GTl+0INzsN 6JI6pBtdHo7kLqu4wPUkdfBDjL5c3cLUkXEafu7t+27mv1P0i8Rb8Ury+A+enEhu2ICB xWKtsRhfvlTgmkcTZGgFaDV5mSfphYCHGOo7o= 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=/9J16zTMj+xkiz3SwiR2BYYmrKOcbO95+Sg/9KpSF18=; b=DRbZ32pKqIn+dRzs4WS2KC6wDawlOMODhCNFlGATxZRpCRoPha5bJtehA1jzyQ/eC5 UfOFcZcUqEK2v5LTJZoyUlMABJagUD4SeYCVwVtCcRtCtraVo6nn0ALdIS8/ocP/UilS qlA0GmFcL0olstvVlYxNs5Y0D+vEMCQX8Qeo84d5UVt9E62tkp35D9cxtPgCF3LWNm4p r3re5X3KULS2qXzErDAJ0hZTwVdlxfqdixtBvrYfM+GNCCct5RpkJm497tQ/vQK8SzsD gJ6l49DjFElhG6JfOEXZAu9YAjhaL5q0QH9alg+dV06OCSeA3jYAP6oMgegDBtOD3NOF w2RQ== X-Gm-Message-State: AOAM5309HR/VEeQwFgpWTfviZ814vurBRZEYGDGCstXgqxJz9f23NhDZ RtUgGnwJV34ScbEevIRLnSBKaiGwxs7MUQ== X-Google-Smtp-Source: ABdhPJxHaWs+vTAGZxRFjUSM/NMVYXbJwOTXGyNc+7Iwx2A7wHDVub6RPCM6zMV/Ww73lk9MTgRSRw== X-Received: by 2002:a17:902:768b:b029:12d:306e:9f68 with SMTP id m11-20020a170902768bb029012d306e9f68mr28563964pll.13.1629724371752; Mon, 23 Aug 2021 06:12:51 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:184e:5d20:8fcb:dfcd]) by smtp.gmail.com with ESMTPSA id j4sm18596891pgi.6.2021.08.23.06.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 06:12:50 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Aug 2021 22:12:20 +0900 Message-Id: <20210823131221.1034059-10-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210823131221.1034059-1-hiroh@chromium.org> References: <20210823131221.1034059-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 09/10] android: camera_device: Fill offset and right length in CreateFrameBuffer() 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" CameraDevice::CreateFrameBuffer() fills the length of the buffer to each FrameBuffer::Plane::length. It should rather be the length of plane. This also changes CreateFrameBuffer() to fill offset of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 47 ++++++++++++++++++++--------------- src/android/camera_device.h | 6 ++++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a69b687a..6663817d 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -744,31 +745,35 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) +FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, + libcamera::PixelFormat pixelFormat, + const libcamera::Size &size) { - std::vector planes; + FileDescriptor fd; + /* This assumes all the planes are in the same buffer. */ for (int i = 0; i < camera3buffer->numFds; i++) { - /* Skip unused planes. */ - if (camera3buffer->data[i] == -1) + if (camera3buffer->data[i] != -1) { + fd = FileDescriptor(camera3buffer->data[i]); break; - - FrameBuffer::Plane plane; - plane.fd = FileDescriptor(camera3buffer->data[i]); - if (!plane.fd.isValid()) { - LOG(HAL, Error) << "Failed to obtain FileDescriptor (" - << camera3buffer->data[i] << ") " - << " on plane " << i; - return nullptr; } + } - off_t length = lseek(plane.fd.fd(), 0, SEEK_END); - if (length == -1) { - LOG(HAL, Error) << "Failed to query plane length"; - return nullptr; - } + if (!fd.isValid()) { + LOG(HAL, Fatal) << "No valid fd"; + return nullptr; + } + + CameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ); + if (!buf.isValid()) { + LOG(HAL, Fatal) << "Failed mapping buffer"; + return nullptr; + } - plane.length = length; - planes.push_back(std::move(plane)); + std::vector planes(buf.numPlanes()); + for (size_t i = 0; i < buf.numPlanes(); ++i) { + planes[i].fd = fd; + planes[i].offset = buf.offset(i); + planes[i].length = buf.size(i); } return new FrameBuffer(std::move(planes)); @@ -976,7 +981,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - buffer = createFrameBuffer(*camera3Buffer.buffer); + buffer = createFrameBuffer(*camera3Buffer.buffer, + cameraStream->configuration().pixelFormat, + cameraStream->configuration().size); descriptor.frameBuffers_.emplace_back(buffer); LOG(HAL, Debug) << ss.str() << " (direct)"; break; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index dd9aebba..a5576927 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include @@ -91,7 +93,9 @@ private: void stop(); - libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); + libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer, + libcamera::PixelFormat pixelFormat, + const libcamera::Size &size); void abortRequest(camera3_capture_request_t *request); bool isValidRequest(camera3_capture_request_t *request) const; void notifyShutter(uint32_t frameNumber, uint64_t timestamp);