{"id":8847,"url":"https://patchwork.libcamera.org/api/1.1/patches/8847/?format=json","web_url":"https://patchwork.libcamera.org/patch/8847/","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":"<20200717085410.732308-10-naush@raspberrypi.com>","date":"2020-07-17T08:54:09","name":"[libcamera-devel,v3,09/10] libcamera: pipeline: ipa: raspberrypi: Remove use of FrameBuffer cookie","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e7d99741e85cc02f0ef95d7bd5ad71fed3a10e3a","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8847/mbox/","series":[{"id":1114,"url":"https://patchwork.libcamera.org/api/1.1/series/1114/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1114","date":"2020-07-17T08:54:00","name":"Zero-copy RAW stream work","version":3,"mbox":"https://patchwork.libcamera.org/series/1114/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8847/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8847/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 EE6C3C2E67\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jul 2020 08:54:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BC52F60599;\n\tFri, 17 Jul 2020 10:54:27 +0200 (CEST)","from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72ACB6055F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jul 2020 10:54:24 +0200 (CEST)","by mail-wr1-x430.google.com with SMTP id o11so10156574wrv.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jul 2020 01:54:24 -0700 (PDT)","from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\t92sm14582375wrr.96.2020.07.17.01.54.22\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 17 Jul 2020 01:54:23 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"er1PRJad\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=oX61mZmA+DsZVKrbdODN6011aK+BN+MhiJIs8BWOhqc=;\n\tb=er1PRJadEJcc3dBVDPmuKVNlTYsePd/jD2WHnGtOIuMFfqTTXuIZt4xQmVYz2tI3FP\n\tIm+KoGhc+H2WtNfkcpU8CE2WFkTdxjWff6c6uKrth/0b7J/IlVMEk5sc+BZ/hCo6dpUq\n\tCYW5Ax5pitAWVzhcfcTE5ZhkRplMnQjZsaf9cJUV6hHfQaTIkaNZQlFBGJP45gYrwrZJ\n\toxLd0aJkrJbxGqM19woc3XSkSvnuOZU451e8g64oRA/MSWyQ3sx+gHzMdwDW3Us8bBoo\n\trl19HKeBo2369B70KkISIfmYgpskoNkT5V2XslUjnT8Lr3Gyncq3p3UMhz/SPMCa2eMp\n\t8XAg==","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=oX61mZmA+DsZVKrbdODN6011aK+BN+MhiJIs8BWOhqc=;\n\tb=qtkatRD7KBpKNg3/DGaqLZpfRxBpWYBhenI9FzbLIdZm1+RDcMXdj9u5z9bOcNvOjb\n\tEOkQ0rEwdwF/mpW+lbCmjKMGin2BgNQIHigTFY/Gh5s3TUgvc2XRoebKOGB3Cf2y51Qr\n\tQuz4hDsckZV3JFCYpjiOOQRd+TDx4AtNsWjKlMk0Gutzyj31rojenCSlWZhkuMUWW2UY\n\teMtTJ6qh4pyM131Du1UNEf0an0+rzxCjq/N2Aceg7QRIv2EEp1ditJaBfDUOsZWXTTnF\n\tnkAchwlffYE1EeG7PV/c6aAFiKCj/GFs6G0K7Kp/v6nOZAS4yWttxrvaiIhx7t9fS79+\n\tD9Bg==","X-Gm-Message-State":"AOAM532KmsOz+IbvKnyFHO6j4STkoTLihi/dwgY0Jil/2VPzS1kfjaIY\n\tCGcySYD4E/O5nWga2I5skaVsIv9xqdQ=","X-Google-Smtp-Source":"ABdhPJzL/Q2JbJdxScu7T11YtIrB/QbJ7JPp+9cJ+InW4KCBOkJFryI1ApyFIjsQy0OXkg0ET5FzMw==","X-Received":"by 2002:a05:6000:1283:: with SMTP id\n\tf3mr9315517wrx.106.1594976063569; \n\tFri, 17 Jul 2020 01:54:23 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 17 Jul 2020 09:54:09 +0100","Message-Id":"<20200717085410.732308-10-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200717085410.732308-1-naush@raspberrypi.com>","References":"<20200717085410.732308-1-naush@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 09/10] libcamera: pipeline: ipa:\n\traspberrypi: Remove use of FrameBuffer cookie","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=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The FrameBuffer cookie may be set by the application, so this cannot\nbe set by the pipeline handler as well. Revert to using a simple index\ninto the buffer list to identify buffers passing to and from the IPA.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 60 ++++++++++---------\n .../pipeline/raspberrypi/rpi_stream.cpp       | 14 +++--\n .../pipeline/raspberrypi/rpi_stream.h         |  2 +-\n 3 files changed, 40 insertions(+), 36 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex ce56ad1a..e400c10c 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -888,7 +888,8 @@ int PipelineHandlerRPi::queueAllBuffers(Camera *camera)\n int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n {\n \tRPiCameraData *data = cameraData(camera);\n-\tint count, ret;\n+\tunsigned int index;\n+\tint ret;\n \n \t/*\n \t * Decide how many internal buffers to allocate. For now, simply look\n@@ -908,30 +909,24 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t}\n \n \t/*\n-\t * Add cookies to the ISP Input buffers so that we can link them with\n-\t * the IPA and RPI_IPA_EVENT_SIGNAL_ISP_PREPARE event.\n-\t */\n-\tcount = 0;\n-\tfor (auto const &b : data->unicam_[Unicam::Image].getBuffers()) {\n-\t\tb->setCookie(count++);\n-\t}\n-\n-\t/*\n-\t * Add cookies to the stats and embedded data buffers and link them with\n-\t * the IPA.\n+\t * Link the FrameBuffers with the index of their position in the vector\n+\t * stored in the RPi stream object.\n+\t *\n+\t * This will allow us to identify buffers passed between the pipeline\n+\t * handler and the IPA.\n \t */\n-\tcount = 0;\n+\tindex = 0;\n \tfor (auto const &b : data->isp_[Isp::Stats].getBuffers()) {\n-\t\tb->setCookie(count++);\n-\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | b->cookie(),\n+\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::STATS | index,\n \t\t\t\t\t      .planes = b->planes() });\n+\t\tindex++;\n \t}\n \n-\tcount = 0;\n+\tindex = 0;\n \tfor (auto const &b : data->unicam_[Unicam::Embedded].getBuffers()) {\n-\t\tb->setCookie(count++);\n-\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | b->cookie(),\n+\t\tdata->ipaBuffers_.push_back({ .id = RPiIpaMask::EMBEDDED_DATA | index,\n \t\t\t\t\t      .planes = b->planes() });\n+\t\tindex++;\n \t}\n \n \tdata->ipa_->mapBuffers(data->ipaBuffers_);\n@@ -1120,7 +1115,7 @@ void RPiCameraData::queueFrameAction(unsigned int frame, const IPAOperationData\n \t\tunsigned int bufferId = action.data[0];\n \t\tFrameBuffer *buffer = unicam_[Unicam::Image].getBuffers().at(bufferId);\n \n-\t\tLOG(RPI, Debug) << \"Input re-queue to ISP, buffer id \" << buffer->cookie()\n+\t\tLOG(RPI, Debug) << \"Input re-queue to ISP, buffer id \" << bufferId\n \t\t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n \t\tisp_[Isp::Input].queueBuffer(buffer);\n@@ -1140,12 +1135,14 @@ done:\n void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n {\n \tRPi::RPiStream *stream = nullptr;\n+\tint index;\n \n \tif (state_ == State::Stopped)\n \t\treturn;\n \n \tfor (RPi::RPiStream &s : unicam_) {\n-\t\tif (s.findFrameBuffer(buffer)) {\n+\t\tindex = s.getBufferIndex(buffer);\n+\t\tif (index != -1) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n \t\t}\n@@ -1155,7 +1152,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \tASSERT(stream);\n \n \tLOG(RPI, Debug) << \"Stream \" << stream->name() << \" buffer dequeue\"\n-\t\t\t<< \", buffer id \" << buffer->cookie()\n+\t\t\t<< \", buffer id \" << index\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n \tif (stream == &unicam_[Unicam::Image]) {\n@@ -1195,7 +1192,7 @@ void RPiCameraData::ispInputDequeue(FrameBuffer *buffer)\n \t\treturn;\n \n \tLOG(RPI, Debug) << \"Stream ISP Input buffer complete\"\n-\t\t\t<< \", buffer id \" << buffer->cookie()\n+\t\t\t<< \", buffer id \" << unicam_[Unicam::Image].getBufferIndex(buffer)\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n \t/* The ISP input buffer gets re-queued into Unicam. */\n@@ -1206,12 +1203,14 @@ void RPiCameraData::ispInputDequeue(FrameBuffer *buffer)\n void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n {\n \tRPi::RPiStream *stream = nullptr;\n+\tint index;\n \n \tif (state_ == State::Stopped)\n \t\treturn;\n \n \tfor (RPi::RPiStream &s : isp_) {\n-\t\tif (s.findFrameBuffer(buffer)) {\n+\t\tindex = s.getBufferIndex(buffer);\n+\t\tif (index != -1) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n \t\t}\n@@ -1221,7 +1220,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n \tASSERT(stream);\n \n \tLOG(RPI, Debug) << \"Stream \" << stream->name() << \" buffer complete\"\n-\t\t\t<< \", buffer id \" << buffer->cookie()\n+\t\t\t<< \", buffer id \" << index\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n \n \t/*\n@@ -1231,7 +1230,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n \tif (stream == &isp_[Isp::Stats]) {\n \t\tIPAOperationData op;\n \t\top.operation = RPI_IPA_EVENT_SIGNAL_STAT_READY;\n-\t\top.data = { RPiIpaMask::STATS | buffer->cookie() };\n+\t\top.data = { RPiIpaMask::STATS | static_cast<unsigned int>(index) };\n \t\tipa_->processEvent(op);\n \t} else {\n \t\t/* Any other ISP output can be handed back to the application now. */\n@@ -1450,13 +1449,16 @@ void RPiCameraData::tryRunPipeline()\n \t/* Set our state to say the pipeline is active. */\n \tstate_ = State::Busy;\n \n+\tunsigned int bayerIndex = unicam_[Unicam::Image].getBufferIndex(bayerBuffer);\n+\tunsigned int embeddedIndex = unicam_[Unicam::Embedded].getBufferIndex(embeddedBuffer);\n+\n \tLOG(RPI, Debug) << \"Signalling RPI_IPA_EVENT_SIGNAL_ISP_PREPARE:\"\n-\t\t\t<< \" Bayer buffer id: \" << bayerBuffer->cookie()\n-\t\t\t<< \" Embedded buffer id: \" << embeddedBuffer->cookie();\n+\t\t\t<< \" Bayer buffer id: \" << bayerIndex\n+\t\t\t<< \" Embedded buffer id: \" << embeddedIndex;\n \n \top.operation = RPI_IPA_EVENT_SIGNAL_ISP_PREPARE;\n-\top.data = { RPiIpaMask::EMBEDDED_DATA | embeddedBuffer->cookie(),\n-\t\t    RPiIpaMask::BAYER_DATA | bayerBuffer->cookie() };\n+\top.data = { RPiIpaMask::EMBEDDED_DATA | embeddedIndex,\n+\t\t    RPiIpaMask::BAYER_DATA | bayerIndex };\n \tipa_->processEvent(op);\n }\n \ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\nindex 4818117e..61226e94 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n@@ -179,15 +179,17 @@ void RPiStream::returnBuffer(FrameBuffer *buffer)\n \t}\n }\n \n-bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const\n+int RPiStream::getBufferIndex(FrameBuffer *buffer) const\n {\n \tif (importOnly_)\n-\t\treturn false;\n+\t\treturn -1;\n \n-\tif (std::find(bufferList_.begin(), bufferList_.end(), buffer) != bufferList_.end())\n-\t\treturn true;\n+\t/* Find the buffer in the list, and return the index position. */\n+\tauto it = std::find(bufferList_.begin(), bufferList_.end(), buffer);\n+\tif (it != bufferList_.end())\n+\t\treturn std::distance(bufferList_.begin(), it);\n \n-\treturn false;\n+\treturn -1;\n }\n \n void RPiStream::clearBuffers()\n@@ -200,7 +202,7 @@ void RPiStream::clearBuffers()\n \n int RPiStream::queueToDevice(FrameBuffer *buffer)\n {\n-\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << buffer->cookie()\n+\tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << getBufferIndex(buffer)\n \t\t\t      << \" for \" << name_;\n \n \tint ret = dev_->queueBuffer(buffer);\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\nindex 6c8dfa83..a6fd5c8e 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n@@ -47,7 +47,7 @@ public:\n \tint queueAllBuffers();\n \tint queueBuffer(FrameBuffer *buffer);\n \tvoid returnBuffer(FrameBuffer *buffer);\n-\tbool findFrameBuffer(FrameBuffer *buffer) const;\n+\tint getBufferIndex(FrameBuffer *buffer) const;\n \n private:\n \tvoid clearBuffers();\n","prefixes":["libcamera-devel","v3","09/10"]}