[{"id":2183,"web_url":"https://patchwork.libcamera.org/comment/2183/","msgid":"<20190706121003.GP17685@bigcity.dyn.berto.se>","date":"2019-07-06T12:10:03","subject":"Re: [libcamera-devel] [PATCH 7/9] libcamera: request: Support\n\tbuffer mapping","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your patch, I really like it!\n\nOn 2019-07-05 00:53:32 +0200, Jacopo Mondi wrote:\n> Use the Stream class buffer mapping operation to save the association in\n> the request at Request::findBuffer() time and reverse it with a new\n> operation Request::unmapBuffer() used by the pipeline handler base class\n> at buffer completion time, to return to the applications the Buffer they\n> originally provided with the Request without involving the pipeline\n> handlers in the process.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/request.h        |  4 ++-\n>  src/libcamera/pipeline_handler.cpp |  6 ++--\n>  src/libcamera/request.cpp          | 45 ++++++++++++++++++++++++++++--\n>  3 files changed, 50 insertions(+), 5 deletions(-)\n> \n> diff --git a/include/libcamera/request.h b/include/libcamera/request.h\n> index 70f6d7fa7eeb..3353f037945e 100644\n> --- a/include/libcamera/request.h\n> +++ b/include/libcamera/request.h\n> @@ -36,7 +36,8 @@ public:\n>  \tControlList &controls() { return controls_; }\n>  \tconst std::map<Stream *, Buffer *> &buffers() const { return buffers_; }\n>  \tint setBuffers(const std::map<Stream *, Buffer *> &streamMap);\n> -\tBuffer *findBuffer(Stream *stream) const;\n> +\tBuffer *findBuffer(Stream *stream);\n> +\tBuffer *unmapBuffer(Buffer *streamBuffer);\n>  \n>  \tStatus status() const { return status_; }\n>  \n> @@ -55,6 +56,7 @@ private:\n>  \tControlList controls_;\n>  \tstd::map<Stream *, Buffer *> buffers_;\n>  \tstd::unordered_set<Buffer *> pending_;\n> +\tstd::map<Buffer *, Buffer *> bufferMap_;\n>  \n>  \tStatus status_;\n>  };\n> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\n> index 67b215483847..a47411ecf345 100644\n> --- a/src/libcamera/pipeline_handler.cpp\n> +++ b/src/libcamera/pipeline_handler.cpp\n> @@ -402,8 +402,10 @@ int PipelineHandler::queueRequest(Camera *camera, Request *request)\n>  bool PipelineHandler::completeBuffer(Camera *camera, Request *request,\n>  \t\t\t\t     Buffer *buffer)\n>  {\n> -\tcamera->bufferCompleted.emit(request, buffer);\n> -\treturn request->completeBuffer(buffer);\n> +\tBuffer *requestBuffer = request->unmapBuffer(buffer);\n> +\n> +\tcamera->bufferCompleted.emit(request, requestBuffer);\n> +\treturn request->completeBuffer(requestBuffer);\n>  }\n>  \n>  /**\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index 9ff0abbf119c..0e07d39f8941 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -105,17 +105,58 @@ int Request::setBuffers(const std::map<Stream *, Buffer *> &streamMap)\n>   */\n>  \n>  /**\n> - * \\brief Return the buffer associated with a stream\n> + * \\brief Retrieve the stream buffer associated with a stream\n>   * \\param[in] stream The stream the buffer is associated to\n> + *\n> + * Depending on the configured memory type, the buffers originally provided\n> + * by the application might get mapped to streams internal buffers.\n> + *\n> + * \\sa Stream::mapBuffer()\n> + *\n>   * \\return The buffer associated with the stream, or nullptr if the stream is\n>   * not part of this request\n>   */\n> -Buffer *Request::findBuffer(Stream *stream) const\n> +Buffer *Request::findBuffer(Stream *stream)\n>  {\n>  \tauto it = buffers_.find(stream);\n>  \tif (it == buffers_.end())\n>  \t\treturn nullptr;\n>  \n> +\t/*\n> +\t * Streams with internal memory mode do not need to perform any mapping\n> +\t * between the application provided buffers (part of the request)\n> +\t * and the one actually used by the Stream.\n> +\t *\n> +\t * Streams using externally allocated buffers need to create a mapping\n> +\t * between the application provided buffers and the one used by pipeline\n> +\t * handlers.\n> +\t */\n> +\tBuffer *requestBuffer = it->second;\n> +\tBuffer *mappedBuffer = stream->memoryType() == InternalMemory ?\n> +\t\t\t       it->second : stream->mapBuffer(it->second);\n> +\tbufferMap_[mappedBuffer] = requestBuffer;\n\nnit-pick: This is hard to read.\n\n\n    Buffer *requestBuffer, *mappedBuffer;\n\n    requestBuffer = it->second;\n\n    if (stream->memoryType() == InternalMemory)\n        mappedBuffer = requestBuffer;\n    else\n        mappedBuffer = stream->mapBuffer(requestBuffer);\n\n    bufferMap_[mappedBuffer] = requestBuffer;\n\nWith or without this fixed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> +\n> +\treturn mappedBuffer;\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the application buffer associated with \\a streamBuffer\n> + * \\param streamBuffer The stream buffer returned from Request::findBuffer()\n> + *\n> + * This operation is used by the PipelineHandler base class to retrieve the\n> + * buffer the application originally associated with the stream in the request.\n> + * Depending on the configured memory type, application provided buffers might\n> + * be mapped to streams internal buffers at Request::findBuffer() time.\n> + *\n> + * \\sa Stream::mapBuffer()\n> + *\n> + * \\return The application buffer provided to Request::findBuffer()\n> + */\n> +Buffer *Request::unmapBuffer(Buffer *streamBuffer)\n> +{\n> +\tauto it = bufferMap_.find(streamBuffer);\n> +\tASSERT(it != bufferMap_.end());\n> +\n>  \treturn it->second;\n>  }\n>  \n> -- \n> 2.21.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34B1361568\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  6 Jul 2019 14:10:05 +0200 (CEST)","by mail-lf1-x142.google.com with SMTP id h28so3586293lfj.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 06 Jul 2019 05:10:05 -0700 (PDT)","from localhost (customer-145-14-112-32.stosn.net. [145.14.112.32])\n\tby smtp.gmail.com with ESMTPSA id\n\tj77sm2357006ljb.55.2019.07.06.05.10.03\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tSat, 06 Jul 2019 05:10:03 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=bICMqhKt+3n4dZLMrFQhW9yj22hRLEBSBSKd0wR4S5c=;\n\tb=jKroPMSer299o8U4ee8GaQmbhj4ywOVo9I7nCtrvK3VimjwvjjgRJtBZv65Ce9Rse1\n\tVhxAdkYCCRgbC/15Xjf1ffU8BohXA2sUkYJ9LW5V8bOFlr4i0M/4kTQNMrSB5/S/PzMK\n\tvc3buKZ/G75hf94sDuUCFQGrad6MYtn9NHcWVv9WtsFTsKm6BSVR4SKAeDWCXh0TN3oC\n\tuc+e3++WLbFeFbiIE3jjiqUe0kXLGNbqdzkR8ssmVP8hHU7K8R6AVg4V1AAWx3/iLUc8\n\tAeQSsfVtEDGt+MVSdcAccsh0Ab/TULoOpXP4jF6K8Khd8KOwVnB9NAX/STUJDwENCSdG\n\t25dQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=bICMqhKt+3n4dZLMrFQhW9yj22hRLEBSBSKd0wR4S5c=;\n\tb=QYDzkkMTQTIiODPQm6MlJFicCcFBlXFlOrsW/BQg/GjULJVnjPnhGszozpo6v3FB+x\n\tlTZnyKWCFa/FqeZyp/Jkb5VeAJjGx9bUTqI/qwS8UcUTw+j1epzkuCchbCbTwyG8c8nn\n\txeDLBzV8CPQVQe8cZlnCdwfn4Dz8VD1wT6pdtyBtqgDFiYVVjWGbLKvcyjC3MIBEIgPe\n\t/1Sief5xzArOZ6M2i9uB5OwR48LKvllzDAgatHi2P44P+gEVibk+97ZkfguxpjfFHk1s\n\taGWYnfxPvo1lD9apjb5qJ/3DsByRBsFm62kF4DqQnsejSQnDOWSK9c+mqQWwXJMkYReM\n\tFHnA==","X-Gm-Message-State":"APjAAAXB9vwHJOkxy2LPUDySRumWRvKoUPLKVuZexnOHeDwACRwiwlb5\n\tLElWhG8dGJdO6Tg4VO9IUj/JAAXgZFg=","X-Google-Smtp-Source":"APXvYqzyPuQexp8JMOdLEeBy22K2AQsf0qxxjdyggwUeLGSez/QfeLAFLMfWQTM9HWfaXdTwxXBdCQ==","X-Received":"by 2002:a19:48c5:: with SMTP id\n\tv188mr4072404lfa.69.1562415004658; \n\tSat, 06 Jul 2019 05:10:04 -0700 (PDT)","Date":"Sat, 6 Jul 2019 14:10:03 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190706121003.GP17685@bigcity.dyn.berto.se>","References":"<20190704225334.26170-1-jacopo@jmondi.org>\n\t<20190704225334.26170-8-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190704225334.26170-8-jacopo@jmondi.org>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 7/9] libcamera: request: Support\n\tbuffer mapping","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Sat, 06 Jul 2019 12:10:05 -0000"}}]