{"id":13452,"url":"https://patchwork.libcamera.org/api/1.1/patches/13452/?format=json","web_url":"https://patchwork.libcamera.org/patch/13452/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210823131221.1034059-10-hiroh@chromium.org>","date":"2021-08-23T13:12:20","name":"[libcamera-devel,RFC,v2,09/10] android: camera_device: Fill offset and right length in CreateFrameBuffer()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f7482c0c1c399a2cebeb6a17bba064bb7634d7bf","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13452/mbox/","series":[{"id":2386,"url":"https://patchwork.libcamera.org/api/1.1/series/2386/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2386","date":"2021-08-23T13:12:11","name":"Add offset to FrameBuffer::Plane","version":2,"mbox":"https://patchwork.libcamera.org/series/2386/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13452/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13452/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 456ECBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 13:12:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0C767688D2;\n\tMon, 23 Aug 2021 15:12:55 +0200 (CEST)","from mail-pl1-x632.google.com (mail-pl1-x632.google.com\n\t[IPv6:2607:f8b0:4864:20::632])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 821C86890E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 15:12:53 +0200 (CEST)","by mail-pl1-x632.google.com with SMTP id x15so696955plg.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 06:12:53 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:184e:5d20:8fcb:dfcd])\n\tby smtp.gmail.com with ESMTPSA id\n\tj4sm18596891pgi.6.2021.08.23.06.12.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Aug 2021 06:12:50 -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=\"EZqGupbA\"; 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=/9J16zTMj+xkiz3SwiR2BYYmrKOcbO95+Sg/9KpSF18=;\n\tb=EZqGupbASLja44QyjTyBDa4ro8KFc/eJsUMAF66IIe6Dbc36lKecpHu9GTl+0INzsN\n\t6JI6pBtdHo7kLqu4wPUkdfBDjL5c3cLUkXEafu7t+27mv1P0i8Rb8Ury+A+enEhu2ICB\n\txWKtsRhfvlTgmkcTZGgFaDV5mSfphYCHGOo7o=","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=/9J16zTMj+xkiz3SwiR2BYYmrKOcbO95+Sg/9KpSF18=;\n\tb=DRbZ32pKqIn+dRzs4WS2KC6wDawlOMODhCNFlGATxZRpCRoPha5bJtehA1jzyQ/eC5\n\tUfOFcZcUqEK2v5LTJZoyUlMABJagUD4SeYCVwVtCcRtCtraVo6nn0ALdIS8/ocP/UilS\n\tqlA0GmFcL0olstvVlYxNs5Y0D+vEMCQX8Qeo84d5UVt9E62tkp35D9cxtPgCF3LWNm4p\n\tr3re5X3KULS2qXzErDAJ0hZTwVdlxfqdixtBvrYfM+GNCCct5RpkJm497tQ/vQK8SzsD\n\tgJ6l49DjFElhG6JfOEXZAu9YAjhaL5q0QH9alg+dV06OCSeA3jYAP6oMgegDBtOD3NOF\n\tw2RQ==","X-Gm-Message-State":"AOAM5309HR/VEeQwFgpWTfviZ814vurBRZEYGDGCstXgqxJz9f23NhDZ\n\tRtUgGnwJV34ScbEevIRLnSBKaiGwxs7MUQ==","X-Google-Smtp-Source":"ABdhPJxHaWs+vTAGZxRFjUSM/NMVYXbJwOTXGyNc+7Iwx2A7wHDVub6RPCM6zMV/Ww73lk9MTgRSRw==","X-Received":"by 2002:a17:902:768b:b029:12d:306e:9f68 with SMTP id\n\tm11-20020a170902768bb029012d306e9f68mr28563964pll.13.1629724371752; \n\tMon, 23 Aug 2021 06:12:51 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH v2 09/10] 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>\n---\n src/android/camera_device.cpp | 47 ++++++++++++++++++++---------------\n src/android/camera_device.h   |  6 ++++-\n 2 files changed, 32 insertions(+), 21 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex a69b687a..6663817d 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,35 @@ 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/* This assumes all the planes are in the same buffer. */\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 mapping buffer\";\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 +981,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","RFC","v2","09/10"]}