{"id":11143,"url":"https://patchwork.libcamera.org/api/patches/11143/?format=json","web_url":"https://patchwork.libcamera.org/patch/11143/","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":"<20210204100541.657503-6-hiroh@chromium.org>","date":"2021-02-04T10:05:40","name":"[libcamera-devel,RFC,5/6] android: camera_device: Introduce PostProcessorType","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"241a4480d4872ceb6a72394fc15fef02a3ab64d9","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/11143/mbox/","series":[{"id":1650,"url":"https://patchwork.libcamera.org/api/series/1650/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1650","date":"2021-02-04T10:05:35","name":"Support stream mapping in Android HAL adaptation layer","version":1,"mbox":"https://patchwork.libcamera.org/series/1650/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11143/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11143/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 049DFBD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 10:06:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C45286142D;\n\tThu,  4 Feb 2021 11:05:59 +0100 (CET)","from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com\n\t[IPv6:2607:f8b0:4864:20::1036])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B556461438\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 11:05:58 +0100 (CET)","by mail-pj1-x1036.google.com with SMTP id l18so1495794pji.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 04 Feb 2021 02:05:58 -0800 (PST)","from hiroh.c.googlers.com.com\n\t(128.141.236.35.bc.googleusercontent.com. [35.236.141.128])\n\tby smtp.gmail.com with ESMTPSA id\n\tj9sm5808418pgb.47.2021.02.04.02.05.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 04 Feb 2021 02:05:56 -0800 (PST)"],"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=\"oQLd+yoN\"; 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=efVFGRlmisrEE/b5fPi2T6th4c/o9G0mdKmW6grdBQg=;\n\tb=oQLd+yoNW39WURWHzc5JbuBc9jOfCg/hNVOPuHiCqEoPgTx4d1SB2Te+v1UuaLr6QK\n\tb3hxGhNVU/86JKijyV52NwEFPTZbPHVs9QgGSUKhKVMkO/PFZsl2Td7HoRejxPcLRIMv\n\tI1N2OSsIF7zzGJLxpHsGLkNlxJcTC9NY+Zsn0=","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=efVFGRlmisrEE/b5fPi2T6th4c/o9G0mdKmW6grdBQg=;\n\tb=uIgy7XImj1sAsdtfygliE/ERmnH8OkEgpBwZvQcicn/KvFF8cq9JvLT/3pzmItCz+Q\n\tMV/2Bzztxm2fZ4EwQbdXypyaJG+M6mpYcGatZeh7dSZy6HiY7FjL9Oun0vmrHLspOaEt\n\to1JJ/HDabkCjAAb0K/+cjebh144Xu1ZZxgJI2koUK3IlWtUJ7W9LUXWUR8ZtbHtuFtMu\n\tVfKCNhmHuzM7mzJM0IsTtm+4Q66SSdYrGsuLOyx9jZBdNi+ilq7QpRc/2/E3Ufa33+MW\n\tKBMndYzER5tLE5YriNoVrC8A9WHJ2ICILZfPjWskuAIcjrp8CyraGJ1TR8PYU8TjLeTy\n\tGn7A==","X-Gm-Message-State":"AOAM532jzbzSoJVbraF7hgJJaz2OhktvrTnN4IrvFmV0zaM5q4Lf9fvw\n\tqfvynTawFR6d2KVdXlnQmqZIdAUSgN6lTLQm","X-Google-Smtp-Source":"ABdhPJzn5/YFWLWLTJyvEy8zPtlx4CGuGTklpYveBU1/wIcJdvYMrF8i84TRsH9YIYA/Fc4THcTYEw==","X-Received":"by 2002:a17:90a:df46:: with SMTP id\n\tgy6mr7566701pjb.163.1612433157019; \n\tThu, 04 Feb 2021 02:05:57 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  4 Feb 2021 10:05:40 +0000","Message-Id":"<20210204100541.657503-6-hiroh@chromium.org>","X-Mailer":"git-send-email 2.30.0.365.g02bc693789-goog","In-Reply-To":"<20210204100541.657503-1-hiroh@chromium.org>","References":"<20210204100541.657503-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH 5/6] android: camera_device: Introduce\n\tPostProcessorType","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>","Cc":"hanlinchen@chromium.org","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":"This introduces PostProcessorType. It tracks the required post\nprocessor for CameraStream.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_device.cpp | 80 +++++++++++++++++++++++++++++------\n 1 file changed, 68 insertions(+), 12 deletions(-)\n\n--\n2.30.0.365.g02bc693789-goog","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 93dfbcdb..a1ef07b6 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -9,6 +9,7 @@\n #include \"camera_ops.h\"\n #include \"post_processor.h\"\n #include \"jpeg/post_processor_jpeg.h\"\n+#include \"yuv/post_processor_yuv.h\"\n\n #include <fstream>\n #include <sys/mman.h>\n@@ -131,6 +132,17 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {\n \t},\n };\n\n+/* PostProcessorType represents a post processor class.\n+ * None: No post processor\n+ * Jpeg: Jpeg encoding post processor\n+ * Yuv : Yuv post post processor.\n+ */\n+enum class PostProcessorType : uint8_t {\n+\tNone = 0,\n+\tJpeg = 1,\n+\tYuv  = 2,\n+};\n+\n /*\n  * \\struct Camera3StreamConfig\n  * \\brief Data to store StreamConfiguration associated with camera3_stream(s)\n@@ -142,11 +154,16 @@ struct Camera3StreamConfig {\n \tstruct Camera3Stream {\n \t\tCamera3Stream(camera3_stream_t *stream, CameraStream::Type type)\n \t\t\t: stream(stream), type(type) {}\n+\t\tCamera3Stream(camera3_stream_t *stream, CameraStream::Type type,\n+\t\t\t      PostProcessorType postProcessorType)\n+\t\t\t: stream(stream), type(type),\n+\t\t\t  postProcessorType(postProcessorType) {}\n\n \t\tstd::string toString() const;\n\n \t\tcamera3_stream_t *stream = nullptr;\n \t\tCameraStream::Type type = CameraStream::Type::Direct;\n+\t\tPostProcessorType postProcessorType = PostProcessorType::None;\n \t};\n\n \tstd::string toString() const;\n@@ -169,6 +186,15 @@ std::string Camera3StreamConfig::Camera3Stream::toString() const {\n \t\tos << \"Mapped\"; break;\n \t}\n\n+\tswitch (postProcessorType) {\n+\tcase PostProcessorType::None:\n+\t\tos << \"None\"; break;\n+\tcase PostProcessorType::Jpeg:\n+\t\tos << \"Jpeg\"; break;\n+\tcase PostProcessorType::Yuv:\n+\t\tos << \"Yuv\"; break;\n+\t}\n+\n \treturn os.str();\n }\n\n@@ -1554,6 +1580,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \t/* Now handle the MJPEG streams, adding a new stream if required. */\n \tif (jpegStream) {\n \t\tCameraStream::Type type;\n+\t\tPostProcessorType postProcessorType = PostProcessorType::None;\n \t\tint index = -1;\n\n \t\t/* Search for a compatible stream in the non-JPEG ones. */\n@@ -1573,6 +1600,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n\n \t\t\ttype = CameraStream::Type::Mapped;\n \t\t\tindex = i;\n+\t\t\tpostProcessorType = PostProcessorType::Jpeg;\n \t\t\tbreak;\n \t\t}\n\n@@ -1600,14 +1628,18 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \t\t\tindex = streamConfigs.size() - 1;\n \t\t}\n\n-\t\tstreamConfigs[index].streams.push_back({ jpegStream, type });\n+\t\tstreamConfigs[index].streams.push_back(\n+\t\t\t{ jpegStream, type, postProcessorType });\n \t}\n\n \tsortCamera3StreamConfigs(streamConfigs, jpegStream);\n+\n+\tstd::vector<PostProcessorType> postProcessorTypes;\n \tfor (const auto &streamConfig : streamConfigs) {\n \t\tconfig_->addConfiguration(streamConfig.config);\n\n \t\tfor (auto &stream : streamConfig.streams) {\n+\t\t\tpostProcessorTypes.push_back(stream.postProcessorType);\n \t\t\tstreams_.emplace_back(this, stream.type, stream.stream,\n \t\t\t\t\t      config_->size() - 1);\n \t\t\tstream.stream->priv = static_cast<void *>(&streams_.back());\n@@ -1647,21 +1679,46 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \t * StreamConfiguration and set the number of required buffers in\n \t * the Android camera3_stream_t.\n \t */\n-\tfor (CameraStream &cameraStream : streams_) {\n+\tfor (unsigned int i = 0; i < streams_.size(); ++i) {\n+\t\tCameraStream &cameraStream = streams_[i];\n \t\tstd::unique_ptr<PostProcessor> postProcessor;\n\n-\t\tif (cameraStream.type() == CameraStream::Type::Internal ||\n-\t\t    cameraStream.type() == CameraStream::Type::Mapped) {\n+\t\tswitch(postProcessorTypes[i]) {\n+\t\tcase PostProcessorType::None:\n+\t\t\tbreak;\n+\t\tcase PostProcessorType::Jpeg:\n \t\t\tpostProcessor =\n \t\t\t\tstd::make_unique<PostProcessorJpeg>(this);\n+\t\t\tbreak;\n+\t\tcase PostProcessorType::Yuv:\n+\t\t\tpostProcessor = std::make_unique<PostProcessorYuv>();\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (postProcessor) {\n+\t\t\tconst auto &camera3Stream = cameraStream.camera3Stream();\n+\t\t\tStreamConfiguration output;\n+\t\t\tswitch (camera3Stream.format) {\n+\t\t\tcase HAL_PIXEL_FORMAT_BLOB:\n+\t\t\t\toutput.pixelFormat = formats::MJPEG;\n+\t\t\t\tbreak;\n+\t\t\tcase HAL_PIXEL_FORMAT_YCbCr_420_888:\n+\t\t\t\toutput.pixelFormat = formats::NV12;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tLOG(HAL, Error)\n+\t\t\t\t\t<< \"Unexpected format: \"\n+\t\t\t\t\t<< utils::hex(camera3Stream.format);\n+\t\t\t\tbreak;\n+\t\t\t}\n\n-\t\t\tauto output = cameraStream.configuration();\n-\t\t\toutput.pixelFormat = formats::MJPEG;\n-\t\t\tpostProcessor->configure(cameraStream.configuration(),\n-\t\t\t\t\t\t output);\n+\t\t\toutput.size.width = camera3Stream.width;\n+\t\t\toutput.size.height = camera3Stream.height;\n+\t\t\tret = postProcessor->configure(\n+\t\t\t\tcameraStream.configuration(), output);\n \t\t\tif (ret) {\n-\t\t\t\tLOG(HAL, Error) << \"Failed to configure \"\n-\t\t\t\t\t\t<< \"PostProcessorJpeg\";\n+\t\t\t\tLOG(HAL, Error)\n+\t\t\t\t\t<< \"Failed to configure post processor\";\n \t\t\t\treturn ret;\n \t\t\t}\n \t\t}\n@@ -1871,12 +1928,11 @@ void CameraDevice::requestComplete(Request *request)\n \tuint64_t timestamp = buffers.begin()->second->metadata().timestamp;\n \tresultMetadata = getResultMetadata(descriptor, timestamp);\n\n-\t/* Handle any JPEG compression. */\n \tfor (unsigned int i = 0; i < descriptor->numBuffers_; ++i) {\n \t\tCameraStream *cameraStream =\n \t\t\tstatic_cast<CameraStream *>(descriptor->buffers_[i].stream->priv);\n\n-\t\tif (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB)\n+\t\tif (cameraStream->type() == CameraStream::Type::Direct)\n \t\t\tcontinue;\n\n \t\tFrameBuffer *buffer = request->findBuffer(cameraStream->stream());\n","prefixes":["libcamera-devel","RFC","5/6"]}