{"id":15722,"url":"https://patchwork.libcamera.org/api/patches/15722/?format=json","web_url":"https://patchwork.libcamera.org/patch/15722/","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":"<20220426091409.1352047-5-chenghaoyang@chromium.org>","date":"2022-04-26T09:14:09","name":"[libcamera-devel,v3,4/4] Add JEA implementation","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c2d3ff9f5b44c0c35faf1f28ed4af3b1704e3b90","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15722/mbox/","series":[{"id":3071,"url":"https://patchwork.libcamera.org/api/series/3071/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3071","date":"2022-04-26T09:14:05","name":"Add CrOS JEA implementation","version":3,"mbox":"https://patchwork.libcamera.org/series/3071/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15722/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15722/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 67C36C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 26 Apr 2022 09:16:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2643E65648;\n\tTue, 26 Apr 2022 11:16:24 +0200 (CEST)","from mail-pf1-x431.google.com (mail-pf1-x431.google.com\n\t[IPv6:2607:f8b0:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63E1D60431\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Apr 2022 11:16:23 +0200 (CEST)","by mail-pf1-x431.google.com with SMTP id h1so17401953pfv.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Apr 2022 02:16:23 -0700 (PDT)","from chenghaoyang.c.googlers.com.com\n\t(93.135.240.35.bc.googleusercontent.com. [35.240.135.93])\n\tby smtp.gmail.com with ESMTPSA id\n\tw123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.20\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 26 Apr 2022 02:16:21 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1650964584;\n\tbh=BIyWGilt+pzXcH1m7VUHJ0qRsUtbgkSEdIntBenC3lU=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=CT1xThdQHsINz5C+TbulIPoj2fKVCvUFHzW+B2rVKEsxpQJtJXd/ICWWbgD+6Z2bQ\n\twQ3yuNrDd4IMv+YDzJ9bJkbT7zibYRm3ODMAyn04v2hj9Oz8N7ZZ/mWz8IU8ZBBVpM\n\tpL7IoDepaVxLJnjNHJ4yUMWLA5ForRLlyOwLQD0DbnS2FoKrRkIOcBKGKMRtGVsvvy\n\tqciw2ZxCW9imaumXH1VI12LKb/sHx6h2e4zx14tLVETpISTxITVIZ7rkRdBEERn+UF\n\tmeEDoS6OAp+5T53dXII10prZnpGONLjKcCqXK6TIl2MmgZ+ETi4PFz7rRlG8UkK6lJ\n\tVUzH90ObWYsBQ==","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=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=;\n\tb=ZMMZQDizbAs+qpDYog0MLn/Ivi1juhwdNSaEgYxLJadEZKbdH1dNYtzFWoxbvyJKSJ\n\tBmKM8Wv+rT2/B6kGhfLiclVq+pHPJeVaKU2pAjBMjyZiN1axvY4twQCxV1YaWQb3+4yd\n\tEh0CBDVkSJXDPXtcFhxJMor6sX/370YrWn1KE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"ZMMZQDiz\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\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=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=;\n\tb=gG6esJ0EuuLH2fXgohMzjo24BKRsvCiYzy4p21guyQT2xXrTxVC3Y5KziOeJtL3MKP\n\tKwGKduud7f1hpLHJArANSAchE8t03Esv5VgrZbDg1HLRaRH6TI6+q3SclT/O8aurML/b\n\t5QzLSFi89m/2ekdI7XK7WjOjbxsWvmIW/dGefYbEzgmZx7+1OS6KTfPaSPhK9+ztd0QZ\n\t/KRB3161edHwHcqAweHHS0idAfu1Bf39L19LbY4q2u9WQY7f5D/Ul4z/bZCFwzX81kJC\n\tdrv+8Ry6jkKUXVPl2yosT6L0mRBRJbnrYQZrCMDqW94FGDkGIh6QLgeTJzjewVda6EcK\n\tN/aQ==","X-Gm-Message-State":"AOAM533C7eEQAfLUMMtzTnt1iUH+yZyXk6/Pahi8aXwioD5rWbfhdAzn\n\tHD64+xgqW0gEaTO2BfjkTbISvWTz6SKzSinQ","X-Google-Smtp-Source":"ABdhPJxnk3jeWFpG6DBOBdkyoY+B0XbyVcMuPjvdA8RhRJrVv78AFyoyklZwHewOiXu9DMgZKEJGaw==","X-Received":"by 2002:a63:cd0d:0:b0:39c:d48c:67cc with SMTP id\n\ti13-20020a63cd0d000000b0039cd48c67ccmr18958712pgg.606.1650964581614; \n\tTue, 26 Apr 2022 02:16:21 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 26 Apr 2022 09:14:09 +0000","Message-Id":"<20220426091409.1352047-5-chenghaoyang@chromium.org>","X-Mailer":"git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog","In-Reply-To":"<20220426091409.1352047-1-chenghaoyang@chromium.org>","References":"<20220426091409.1352047-1-chenghaoyang@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 4/4] Add JEA implementation","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>","From":"Harvey Yang via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Harvey Yang <chenghaoyang@chromium.org>","Cc":"Harvey Yang <chenghaoyang@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This CL adds JEA implementation to replace Lib Jpeg in cros platform,\nwhere HW accelerator is available.\n\nSigned-off-by: Harvey Yang <chenghaoyang at chromium.org>\n---\n src/android/cros/camera3_hal.cpp              |  3 +\n src/android/jpeg/cros_post_processor_jpeg.cpp | 14 ++++\n src/android/jpeg/encoder_jea.cpp              | 82 +++++++++++++++++++\n src/android/jpeg/encoder_jea.h                | 35 ++++++++\n src/android/jpeg/meson.build                  | 13 ++-\n 5 files changed, 144 insertions(+), 3 deletions(-)\n create mode 100644 src/android/jpeg/cros_post_processor_jpeg.cpp\n create mode 100644 src/android/jpeg/encoder_jea.cpp\n create mode 100644 src/android/jpeg/encoder_jea.h","diff":"diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp\nindex fb863b5f..ea5577f0 100644\n--- a/src/android/cros/camera3_hal.cpp\n+++ b/src/android/cros/camera3_hal.cpp\n@@ -9,8 +9,11 @@\n \n #include \"../camera_hal_manager.h\"\n \n+cros::CameraMojoChannelManagerToken *g_cros_camera_token = nullptr;\n+\n static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token)\n {\n+\tg_cros_camera_token = token;\n }\n \n static void tear_down()\ndiff --git a/src/android/jpeg/cros_post_processor_jpeg.cpp b/src/android/jpeg/cros_post_processor_jpeg.cpp\nnew file mode 100644\nindex 00000000..7020f0d0\n--- /dev/null\n+++ b/src/android/jpeg/cros_post_processor_jpeg.cpp\n@@ -0,0 +1,14 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * cros_post_processor_jpeg.cpp - CrOS JPEG Post Processor\n+ */\n+\n+#include \"encoder_jea.h\"\n+#include \"post_processor_jpeg.h\"\n+\n+void PostProcessorJpeg::SetEncoder()\n+{\n+\tencoder_ = std::make_unique<EncoderJea>();\n+}\ndiff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp\nnew file mode 100644\nindex 00000000..838e8647\n--- /dev/null\n+++ b/src/android/jpeg/encoder_jea.cpp\n@@ -0,0 +1,82 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * encoder_jea.cpp - JPEG encoding using CrOS JEA\n+ */\n+\n+#include \"encoder_jea.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n+\n+#include <cros-camera/camera_mojo_channel_manager_token.h>\n+\n+#include \"../android_framebuffer.h\"\n+\n+extern cros::CameraMojoChannelManagerToken *g_cros_camera_token;\n+\n+EncoderJea::EncoderJea() = default;\n+\n+EncoderJea::~EncoderJea() = default;\n+\n+int EncoderJea::configure(const libcamera::StreamConfiguration &cfg)\n+{\n+\tsize_ = cfg.size;\n+\n+\tif (jpeg_compressor_.get())\n+\t\treturn 0;\n+\n+\tif (g_cros_camera_token == nullptr)\n+\t\treturn -ENOTSUP;\n+\n+\tjpeg_compressor_ = cros::JpegCompressor::GetInstance(g_cros_camera_token);\n+\n+\treturn 0;\n+}\n+\n+int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n+\t\t       libcamera::Span<const uint8_t> exifData,\n+\t\t       unsigned int quality)\n+{\n+\tif (!jpeg_compressor_.get())\n+\t\treturn -1;\n+\n+\tuint32_t out_data_size = 0;\n+\n+\tif (!jpeg_compressor_->CompressImageFromHandle(\n+\t\t    dynamic_cast<const AndroidFrameBuffer *>(\n+\t\t\t    streamBuffer->srcBuffer)\n+\t\t\t    ->getHandle(),\n+\t\t    *streamBuffer->camera3Buffer, size_.width, size_.height, quality,\n+\t\t    exifData.data(), exifData.size(), &out_data_size)) {\n+\t\treturn -1;\n+\t}\n+\n+\treturn out_data_size;\n+}\n+\n+int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t\t  const libcamera::Size &targetSize,\n+\t\t\t\t  unsigned int quality,\n+\t\t\t\t  std::vector<unsigned char> *thumbnail)\n+{\n+\tif (!jpeg_compressor_.get())\n+\t\treturn -1;\n+\n+\tlibcamera::MappedFrameBuffer frame(&source, libcamera::MappedFrameBuffer::MapFlag::Read);\n+\n+\tif (frame.planes().empty())\n+\t\treturn 0;\n+\n+\tuint32_t out_data_size = 0;\n+\n+\tif (!jpeg_compressor_->GenerateThumbnail(frame.planes()[0].data(),\n+\t\t\t\t\t\t size_.width, size_.height, targetSize.width, targetSize.height,\n+\t\t\t\t\t\t quality, thumbnail->size(), thumbnail->data(), &out_data_size)) {\n+\t\treturn -1;\n+\t}\n+\n+\treturn out_data_size;\n+}\ndiff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h\nnew file mode 100644\nindex 00000000..d5c9f1f7\n--- /dev/null\n+++ b/src/android/jpeg/encoder_jea.h\n@@ -0,0 +1,35 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * encoder_jea.h - JPEG encoding using CrOS JEA\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/geometry.h>\n+\n+#include <cros-camera/jpeg_compressor.h>\n+\n+#include \"encoder.h\"\n+\n+class EncoderJea : public Encoder\n+{\n+public:\n+\tEncoderJea();\n+\t~EncoderJea();\n+\n+\tint configure(const libcamera::StreamConfiguration &cfg) override;\n+\tint encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer,\n+\t\t   libcamera::Span<const uint8_t> exifData,\n+\t\t   unsigned int quality) override;\n+\tint generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t      const libcamera::Size &targetSize,\n+\t\t\t      unsigned int quality,\n+\t\t\t      std::vector<unsigned char> *thumbnail) override;\n+\n+private:\n+\tlibcamera::Size size_;\n+\n+\tstd::unique_ptr<cros::JpegCompressor> jpeg_compressor_;\n+};\ndiff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build\nindex 94522dc0..8606acc4 100644\n--- a/src/android/jpeg/meson.build\n+++ b/src/android/jpeg/meson.build\n@@ -4,6 +4,13 @@ android_hal_sources += files([\n     'exif.cpp',\n     'post_processor_jpeg.cpp'])\n \n-android_hal_sources += files(['encoder_libjpeg.cpp',\n-                              'generic_post_processor_jpeg.cpp',\n-                              'thumbnailer.cpp'])\n+platform = get_option('android_platform')\n+if platform == 'generic'\n+    android_hal_sources += files(['encoder_libjpeg.cpp',\n+                                  'generic_post_processor_jpeg.cpp',\n+                                  'thumbnailer.cpp'])\n+elif platform == 'cros'\n+    android_hal_sources += files(['cros_post_processor_jpeg.cpp',\n+                                  'encoder_jea.cpp'])\n+    android_deps += [dependency('libcros_camera')]\n+endif\n","prefixes":["libcamera-devel","v3","4/4"]}