{"id":8667,"url":"https://patchwork.libcamera.org/api/1.1/patches/8667/?format=json","web_url":"https://patchwork.libcamera.org/patch/8667/","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":"<20200706230240.2482100-8-kieran.bingham@ideasonboard.com>","date":"2020-07-06T23:02:39","name":"[libcamera-devel,v5,7/8] android: camera_device: Add buffers for each stream to Requests","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0f9539ee9eeb6b466128ff3e004ce69777486003","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8667/mbox/","series":[{"id":1089,"url":"https://patchwork.libcamera.org/api/1.1/series/1089/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1089","date":"2020-07-06T23:02:32","name":"android: Multi-stream support","version":5,"mbox":"https://patchwork.libcamera.org/series/1089/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8667/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8667/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 1F11DBD794\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Jul 2020 23:02:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DD9EA60E88;\n\tTue,  7 Jul 2020 01:02:51 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47EA1603AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Jul 2020 01:02:49 +0200 (CEST)","from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net\n\t[86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B7C16D6E;\n\tTue,  7 Jul 2020 01:02:48 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"qmDOsRbD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594076569;\n\tbh=+FO5DmWHqWFlDyA7b0Cxg8sFQGBG6ld2gqETh9Nmp9o=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qmDOsRbDBk4Bg6fqo5ODPhY1Rf4ZvWsgM3PXo9PPfADwcBcSYkuw0JLccahx7r0+x\n\t/V9RN36I4bOEyFJ6kyyoPloqMR5lbnAMOlbbKOq1ePW4eM8xALjelaNCyRh8/WFyC4\n\txZrOyAMAIB2HYK1Lf2k8Y0fqb2EA7cGBwN5l/9bA=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Tue,  7 Jul 2020 00:02:39 +0100","Message-Id":"<20200706230240.2482100-8-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200706230240.2482100-1-kieran.bingham@ideasonboard.com>","References":"<20200706230240.2482100-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v5 7/8] android: camera_device: Add\n\tbuffers for each stream to Requests","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>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Construct a FrameBuffer for every buffer given in the camera3Request\nand add it to the libcamera Request on the appropriate stream.\n\nThe correct stream is obtained from the private data of the camera3_stream\nassociated with the camera3_buffer.\n\nComments regarding supporting only one buffer are now removed, and\nFrameBuffers have their lifetime tracked in the Camera3RequestDescriptor\nto ensure they are released when the Request is completed.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 54 +++++++++++++++++++----------------\n src/android/camera_device.h   |  1 +\n 2 files changed, 31 insertions(+), 24 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 6d060e0c40e5..b13729e84abf 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -98,6 +98,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor(\n \t: frameNumber(frameNumber), numBuffers(numBuffers)\n {\n \tbuffers = new camera3_stream_buffer_t[numBuffers];\n+\tframeBuffers.reserve(numBuffers);\n }\n \n CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor()\n@@ -990,6 +991,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \t\tconfig_->addConfiguration(streamConfiguration);\n \n \t\tstreams_[i].index = streamIndex++;\n+\t\tstream->priv = static_cast<void *>(&streams_[i]);\n \t}\n \n \tswitch (config_->validate()) {\n@@ -1048,9 +1050,6 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer\n \n int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n {\n-\tStreamConfiguration *streamConfiguration = &config_->at(0);\n-\tStream *stream = streamConfiguration->stream();\n-\n \tif (camera3Request->num_output_buffers != 1) {\n \t\tLOG(HAL, Error) << \"Invalid number of output buffers: \"\n \t\t\t\t<< camera3Request->num_output_buffers;\n@@ -1088,30 +1087,35 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\tcamera_->createRequest(reinterpret_cast<uint64_t>(descriptor));\n \n \tfor (unsigned int i = 0; i < descriptor->numBuffers; ++i) {\n+\t\tCameraStream *cameraStream = static_cast<CameraStream *>(camera3Buffers[i].stream->priv);\n+\n \t\t/*\n \t\t * Keep track of which stream the request belongs to and store\n \t\t * the native buffer handles.\n-\t\t *\n-\t\t * \\todo Currently we only support one capture buffer. Copy\n-\t\t * all of them to be ready once we'll support more.\n \t\t */\n \t\tdescriptor->buffers[i].stream = camera3Buffers[i].stream;\n \t\tdescriptor->buffers[i].buffer = camera3Buffers[i].buffer;\n-\t}\n \n-\t/*\n-\t * Create a libcamera buffer using the dmabuf descriptors of the first\n-\t * and (currently) only supported request buffer.\n-\t */\n-\tFrameBuffer *buffer = createFrameBuffer(*camera3Buffers[0].buffer);\n-\tif (!buffer) {\n-\t\tLOG(HAL, Error) << \"Failed to create buffer\";\n+\t\t/*\n+\t\t * Create a libcamera buffer using the dmabuf descriptors of the\n+\t\t * first and (currently) only supported request buffer.\n+\t\t * The FrameBuffer is directly associated with the\n+\t\t * Camera3RequestDescriptor for lifetime management only.\n+\t\t */\n+\t\tFrameBuffer *buffer = createFrameBuffer(*camera3Buffers[i].buffer);\n+\t\tif (!buffer) {\n+\t\t\tLOG(HAL, Error) << \"Failed to create buffer\";\n \t\tdelete request;\n-\t\tdelete descriptor;\n-\t\treturn -ENOMEM;\n-\t}\n+\t\t\tdelete descriptor;\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\t\tdescriptor->frameBuffers.emplace_back(buffer);\n \n-\trequest->addBuffer(stream, buffer);\n+\t\tStreamConfiguration *streamConfiguration = &config_->at(cameraStream->index);\n+\t\tStream *stream = streamConfiguration->stream();\n+\n+\t\trequest->addBuffer(stream, buffer);\n+\t}\n \n \tint ret = camera_->queueRequest(request);\n \tif (ret) {\n@@ -1127,7 +1131,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n void CameraDevice::requestComplete(Request *request)\n {\n \tconst std::map<Stream *, FrameBuffer *> &buffers = request->buffers();\n-\tFrameBuffer *buffer = buffers.begin()->second;\n \tcamera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK;\n \tstd::unique_ptr<CameraMetadata> resultMetadata;\n \n@@ -1145,10 +1148,6 @@ void CameraDevice::requestComplete(Request *request)\n \tcaptureResult.frame_number = descriptor->frameNumber;\n \tcaptureResult.num_output_buffers = descriptor->numBuffers;\n \tfor (unsigned int i = 0; i < descriptor->numBuffers; ++i) {\n-\t\t/*\n-\t\t * \\todo Currently we only support one capture buffer. Prepare\n-\t\t * all of them to be ready once we'll support more.\n-\t\t */\n \t\tdescriptor->buffers[i].acquire_fence = -1;\n \t\tdescriptor->buffers[i].release_fence = -1;\n \t\tdescriptor->buffers[i].status = status;\n@@ -1156,6 +1155,14 @@ void CameraDevice::requestComplete(Request *request)\n \tcaptureResult.output_buffers =\n \t\tconst_cast<const camera3_stream_buffer_t *>(descriptor->buffers);\n \n+\t/*\n+\t * \\todo The timestamp used for the metadata is currently always taken\n+\t * from the first buffer (which may be the first stream) in the Request.\n+\t * It might be appropriate to return a 'correct' (as determined by\n+\t * pipeline handlers) timestamp in the Request itself.\n+\t */\n+\tFrameBuffer *buffer = buffers.begin()->second;\n+\n \tif (status == CAMERA3_BUFFER_STATUS_OK) {\n \t\tnotifyShutter(descriptor->frameNumber,\n \t\t\t      buffer->metadata().timestamp);\n@@ -1180,7 +1187,6 @@ void CameraDevice::requestComplete(Request *request)\n \tcallbacks_->process_capture_result(callbacks_, &captureResult);\n \n \tdelete descriptor;\n-\tdelete buffer;\n }\n \n std::string CameraDevice::logPrefix() const\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex d00f617b09a6..5b8b9c3e26e2 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -70,6 +70,7 @@ private:\n \t\tuint32_t frameNumber;\n \t\tuint32_t numBuffers;\n \t\tcamera3_stream_buffer_t *buffers;\n+\t\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers;\n \t};\n \n \tstruct Camera3StreamConfiguration {\n","prefixes":["libcamera-devel","v5","7/8"]}