From patchwork Thu Aug 26 11:25:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13509 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 2D3ADC3244 for ; Thu, 26 Aug 2021 11:26:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9152F6891F; Thu, 26 Aug 2021 13:26:03 +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="KiN1JA4v"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69D1068918 for ; Thu, 26 Aug 2021 13:26:02 +0200 (CEST) Received: by mail-pg1-x52b.google.com with SMTP id x4so2823468pgh.1 for ; Thu, 26 Aug 2021 04:26:02 -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=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=; b=KiN1JA4vNgSFS/GFeWQ117CSQ0pZw/0sE5i9Ifls8OLYAM6DkAFz4JkGkcOCI59/OU wTUInstE/0lXXIIY9MCMeWoUSFNQexW2hwgeH6+WjZLocZMxx73vyyqH4VLbF1FWWVgW j//9c2HDauX+Pt9NKC/CX4JdR15IcEWxF/fAE= 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=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=; b=M6jhEXHUF4xHxMR7j6Aytuw4QvXsLNNJ3Wql2vLHuKT9ODjE7L045iciRcpw2i7oWm KpbADWMRG5SmPpqXnprCaXvwfM+khzLs5Bbpf2uHaqqt9Gzw8KwqfSSPzrGXT9BB6GyJ VRxK4LA+5LdC1XoBNFBVdu7YMOuCtNKcWb3iODglh0/8r7aCp0y3mMDgnOHK0eDxEFvq pYNn7x1u5kL1Epso3kmpGyQy+feiVocXAli9RggpoNMC0WKnC3tY5hfINX+4YRLVSvhV 2+bID+p4EwpMoYQYL/b8LkX7PwBKhLTwzbIcjd05cmTKlYErPVuigXpwCUqyg3Pw9z56 0NtA== X-Gm-Message-State: AOAM532xGmgxQXM3/t5gmtlAzoWbiujuHozUvf3hqnjN6R691J5R6yPs VKejy7MCYc6AM8U7mqULJMRz6XiMFwV2hw== X-Google-Smtp-Source: ABdhPJzdTPg7K9W9ptJi36NcIqoCr1SSQDX5BlGK97BN/ZTBsX/GXMquTAbs2a8GZ7KT3pXTYDHxrQ== X-Received: by 2002:a63:2f04:: with SMTP id v4mr2916530pgv.380.1629977160653; Thu, 26 Aug 2021 04:26:00 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a5bc:b3dd:7208:bec1]) by smtp.gmail.com with ESMTPSA id s29sm3472057pgl.38.2021.08.26.04.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:59 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:38 +0900 Message-Id: <20210826112539.170694-9-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210826112539.170694-1-hiroh@chromium.org> References: <20210826112539.170694-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 8/9] 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 | 52 +++++++++++++++++++++-------------- src/android/camera_device.h | 6 +++- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a69b687a..4702b332 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,40 @@ 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 dmabuf. + * + * \todo Verify that this assumption holds, fstat() can be used to check + * if two fds refer to the same dmabuf. + */ 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 to create CameraBuffer"; + 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 +986,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);