{"id":13509,"url":"https://patchwork.libcamera.org/api/patches/13509/?format=json","web_url":"https://patchwork.libcamera.org/patch/13509/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210826112539.170694-9-hiroh@chromium.org>","date":"2021-08-26T11:25:38","name":"[libcamera-devel,v3,8/9] android: camera_device: Fill offset and right length in CreateFrameBuffer()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"ca6429f73d98f1261c97ba1290d4afe584215653","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13509/mbox/","series":[{"id":2398,"url":"https://patchwork.libcamera.org/api/series/2398/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2398","date":"2021-08-26T11:25:30","name":"Add offset to FrameBuffer::Plane","version":3,"mbox":"https://patchwork.libcamera.org/series/2398/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13509/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13509/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2D3ADC3244\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Aug 2021 11:26:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9152F6891F;\n\tThu, 26 Aug 2021 13:26:03 +0200 (CEST)","from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com\n\t[IPv6:2607:f8b0:4864:20::52b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 69D1068918\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 13:26:02 +0200 (CEST)","by mail-pg1-x52b.google.com with SMTP id x4so2823468pgh.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 04:26:02 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:a5bc:b3dd:7208:bec1])\n\tby smtp.gmail.com with ESMTPSA id\n\ts29sm3472057pgl.38.2021.08.26.04.25.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 26 Aug 2021 04:25:59 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"KiN1JA4v\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=;\n\tb=KiN1JA4vNgSFS/GFeWQ117CSQ0pZw/0sE5i9Ifls8OLYAM6DkAFz4JkGkcOCI59/OU\n\twTUInstE/0lXXIIY9MCMeWoUSFNQexW2hwgeH6+WjZLocZMxx73vyyqH4VLbF1FWWVgW\n\tj//9c2HDauX+Pt9NKC/CX4JdR15IcEWxF/fAE=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=;\n\tb=M6jhEXHUF4xHxMR7j6Aytuw4QvXsLNNJ3Wql2vLHuKT9ODjE7L045iciRcpw2i7oWm\n\tKpbADWMRG5SmPpqXnprCaXvwfM+khzLs5Bbpf2uHaqqt9Gzw8KwqfSSPzrGXT9BB6GyJ\n\tVRxK4LA+5LdC1XoBNFBVdu7YMOuCtNKcWb3iODglh0/8r7aCp0y3mMDgnOHK0eDxEFvq\n\tpYNn7x1u5kL1Epso3kmpGyQy+feiVocXAli9RggpoNMC0WKnC3tY5hfINX+4YRLVSvhV\n\t2+bID+p4EwpMoYQYL/b8LkX7PwBKhLTwzbIcjd05cmTKlYErPVuigXpwCUqyg3Pw9z56\n\t0NtA==","X-Gm-Message-State":"AOAM532xGmgxQXM3/t5gmtlAzoWbiujuHozUvf3hqnjN6R691J5R6yPs\n\tVKejy7MCYc6AM8U7mqULJMRz6XiMFwV2hw==","X-Google-Smtp-Source":"ABdhPJzdTPg7K9W9ptJi36NcIqoCr1SSQDX5BlGK97BN/ZTBsX/GXMquTAbs2a8GZ7KT3pXTYDHxrQ==","X-Received":"by 2002:a63:2f04:: with SMTP id v4mr2916530pgv.380.1629977160653;\n\tThu, 26 Aug 2021 04:26:00 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 8/9] android: camera_device: Fill\n\toffset and right length in CreateFrameBuffer()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"CameraDevice::CreateFrameBuffer() fills the length of the buffer to\neach FrameBuffer::Plane::length. It should rather be the length of\nplane. This also changes CreateFrameBuffer() to fill offset of\nFrameBuffer::Plane.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------\n src/android/camera_device.h   |  6 +++-\n 2 files changed, 37 insertions(+), 21 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex a69b687a..4702b332 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -12,6 +12,7 @@\n \n #include <algorithm>\n #include <fstream>\n+#include <sys/mman.h>\n #include <unistd.h>\n #include <vector>\n \n@@ -744,31 +745,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \treturn 0;\n }\n \n-FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)\n+FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,\n+\t\t\t\t\t     libcamera::PixelFormat pixelFormat,\n+\t\t\t\t\t     const libcamera::Size &size)\n {\n-\tstd::vector<FrameBuffer::Plane> planes;\n+\tFileDescriptor fd;\n+\t/*\n+\t * This assumes all the planes are in the same dmabuf.\n+\t *\n+         * \\todo Verify that this assumption holds, fstat() can be used to check\n+         * if two fds refer to the same dmabuf.\n+\t */\n \tfor (int i = 0; i < camera3buffer->numFds; i++) {\n-\t\t/* Skip unused planes. */\n-\t\tif (camera3buffer->data[i] == -1)\n+\t\tif (camera3buffer->data[i] != -1) {\n+\t\t\tfd = FileDescriptor(camera3buffer->data[i]);\n \t\t\tbreak;\n-\n-\t\tFrameBuffer::Plane plane;\n-\t\tplane.fd = FileDescriptor(camera3buffer->data[i]);\n-\t\tif (!plane.fd.isValid()) {\n-\t\t\tLOG(HAL, Error) << \"Failed to obtain FileDescriptor (\"\n-\t\t\t\t\t<< camera3buffer->data[i] << \") \"\n-\t\t\t\t\t<< \" on plane \" << i;\n-\t\t\treturn nullptr;\n \t\t}\n+\t}\n \n-\t\toff_t length = lseek(plane.fd.fd(), 0, SEEK_END);\n-\t\tif (length == -1) {\n-\t\t\tLOG(HAL, Error) << \"Failed to query plane length\";\n-\t\t\treturn nullptr;\n-\t\t}\n+\tif (!fd.isValid()) {\n+\t\tLOG(HAL, Fatal) << \"No valid fd\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tCameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ);\n+\tif (!buf.isValid()) {\n+\t\tLOG(HAL, Fatal) << \"Failed to create CameraBuffer\";\n+\t\treturn nullptr;\n+\t}\n \n-\t\tplane.length = length;\n-\t\tplanes.push_back(std::move(plane));\n+\tstd::vector<FrameBuffer::Plane> planes(buf.numPlanes());\n+\tfor (size_t i = 0; i < buf.numPlanes(); ++i) {\n+\t\tplanes[i].fd = fd;\n+\t\tplanes[i].offset = buf.offset(i);\n+\t\tplanes[i].length = buf.size(i);\n \t}\n \n \treturn new FrameBuffer(std::move(planes));\n@@ -976,7 +986,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\t * associate it with the Camera3RequestDescriptor for\n \t\t\t * lifetime management only.\n \t\t\t */\n-\t\t\tbuffer = createFrameBuffer(*camera3Buffer.buffer);\n+\t\t\tbuffer = createFrameBuffer(*camera3Buffer.buffer,\n+\t\t\t\t\t\t   cameraStream->configuration().pixelFormat,\n+\t\t\t\t\t\t   cameraStream->configuration().size);\n \t\t\tdescriptor.frameBuffers_.emplace_back(buffer);\n \t\t\tLOG(HAL, Debug) << ss.str() << \" (direct)\";\n \t\t\tbreak;\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex dd9aebba..a5576927 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -21,6 +21,8 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/framebuffer.h>\n+#include <libcamera/geometry.h>\n+#include <libcamera/pixel_format.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n@@ -91,7 +93,9 @@ private:\n \n \tvoid stop();\n \n-\tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);\n+\tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer,\n+\t\t\t\t\t\t  libcamera::PixelFormat pixelFormat,\n+\t\t\t\t\t\t  const libcamera::Size &size);\n \tvoid abortRequest(camera3_capture_request_t *request);\n \tbool isValidRequest(camera3_capture_request_t *request) const;\n \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n","prefixes":["libcamera-devel","v3","8/9"]}