{"id":18266,"url":"https://patchwork.libcamera.org/api/1.1/patches/18266/?format=json","web_url":"https://patchwork.libcamera.org/patch/18266/","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":"<20230208033319.1361109-6-chenghaoyang@google.com>","date":"2023-02-08T03:33:19","name":"[libcamera-devel,v10,5/5] android: jpeg: Add JEA implementation","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"6c8abc2b994ba3a762015a32f042e4607b75e2d6","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/1.1/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18266/mbox/","series":[{"id":3743,"url":"https://patchwork.libcamera.org/api/1.1/series/3743/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3743","date":"2023-02-08T03:33:14","name":"Add CrOS JEA implementation","version":10,"mbox":"https://patchwork.libcamera.org/series/3743/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18266/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18266/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 EB7BBC324D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Feb 2023 03:33:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 85566625FF;\n\tWed,  8 Feb 2023 04:33:35 +0100 (CET)","from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com\n\t[IPv6:2607:f8b0:4864:20::62a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 801D6625FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Feb 2023 04:33:31 +0100 (CET)","by mail-pl1-x62a.google.com with SMTP id w5so7841934plg.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Feb 2023 19:33:31 -0800 (PST)","from chenghaoyang-low.c.googlers.com.com\n\t(46.165.189.35.bc.googleusercontent.com. [35.189.165.46])\n\tby smtp.gmail.com with ESMTPSA id\n\te9-20020a170902784900b00194c82c2a7bsm9621963pln.224.2023.02.07.19.33.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Feb 2023 19:33:30 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1675827215;\n\tbh=8heM0wgJp2Nb8ziqYzQ/6brIKwImR7elaz4ft9BL748=;\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=eBMN8YRdzOlQEikk10QOqES056aL5T8uyrHphsT4l1wi5MWEP8w+m4zE7m1c+6WgC\n\tUp6IdQgGoqzfNvjUBgAkHDRFWL4TmUFshw2NkOgvtoU2+LyWV0DUieOx94X5W4Do2m\n\tdDnx7dz1NtBn6wvcvTMbSoihlSleFoZlOrAjessdRcsbuuNIV2lrDtehOXXW+fBidP\n\t1nt/O478u5maa2AD67RJpH0pNGNF5t0vSUGybT+7tw6/FhIQPvZp8McuRhWjIBYT+F\n\tK9z00vGfZUsWfiw1IbIt4s3BRpOsqRtk9jVmEgTNIHORBKs1ZS8fWZQEKvP8N20E7t\n\tL96t7lJAQ9Z8Q==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=nZnf86n3l5NZDFZUhXa66wE+AHBO/uzfnPJ6GMpQuUk=;\n\tb=PtFaoL8Pv4u9LFR83qjPmGK1CVIPmPq4FHnHj05aEMxwK0oOGm3xH7hXbW+ajgCWQ3\n\tnOjPjjAXOVuKHiEtj02XvduZCv6vlOi25zAE5QYt1+5ekbZaVWSQv4LsbSQAZYSmMQ8J\n\t9aLRw5mY3lzF8hb+B60UrTVPfNFtx3nek1WEg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"PtFaoL8P\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=nZnf86n3l5NZDFZUhXa66wE+AHBO/uzfnPJ6GMpQuUk=;\n\tb=hXe40ogO409kBHxnHs1uNOd+++LfwaR1hI+iCSx7bCmG8zYcKAu+txfquWUCvYIB6q\n\tMKz7AuGkAX6b5aCkRZwuf4vCqWAAFZEN2qFe4I8p3dyihpHMlDv5F1h23g94crYI1yqX\n\tjpElJsRw8RnswmT/6IqqJJjk57zvFuYTaDqnAK4l1xxO5q40u6MHfglr8MDst7qZTxZW\n\tVW5FSlka3k8v4yq2L24v+YE7dhdvmqudEWFMvcbDlTw7pp1DkPaAg9sLrzp5ANJ4d+Ft\n\tQbjRk9808CAVMp+GthsMKC0eC0NC8deQ3e9bTxncsilbjhIPXYyrjsZfKtiOwhdnYzGu\n\tNlmA==","X-Gm-Message-State":"AO0yUKUaQttX4ItvwE7h/rSRxkNCseEfIYkYEToU79r8DcK9UTxoAzHf\n\totjDJ0s5P56dwfKYgXQrq43Z07sm9gThITay","X-Google-Smtp-Source":"AK7set/SemJ9mRb8HP7T4qdIM4ANI+IhibVIEfFGOM32sTw0UX+RsxN3lFzRFGZ28UFLK+PtUaaMUQ==","X-Received":"by 2002:a17:902:e0d4:b0:199:cf2:4bea with SMTP id\n\te20-20020a170902e0d400b001990cf24beamr4526841pla.66.1675827210836; \n\tTue, 07 Feb 2023 19:33:30 -0800 (PST)","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  8 Feb 2023 03:33:19 +0000","Message-Id":"<20230208033319.1361109-6-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.39.1.519.gcb327c4b5f-goog","In-Reply-To":"<20230208033319.1361109-1-chenghaoyang@google.com>","References":"<20230208033319.1361109-1-chenghaoyang@google.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v10 5/5] android: jpeg: Add JEA\n\timplementation","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":"From: Harvey Yang <chenghaoyang@chromium.org>\n\nThis patch adds JEA implementation to replace libjpeg in CrOS platform,\nwhere hardware accelerator is available.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n src/android/cros/camera3_hal.cpp         |  4 +-\n src/android/cros_mojo_token.h            | 12 +++++\n src/android/jpeg/encoder_jea.cpp         | 56 ++++++++++++++++++++++++\n src/android/jpeg/encoder_jea.h           | 31 +++++++++++++\n src/android/jpeg/meson.build             | 10 ++++-\n src/android/jpeg/post_processor_jpeg.cpp |  8 ++++\n 6 files changed, 118 insertions(+), 3 deletions(-)\n create mode 100644 src/android/cros_mojo_token.h\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..71acb441 100644\n--- a/src/android/cros/camera3_hal.cpp\n+++ b/src/android/cros/camera3_hal.cpp\n@@ -8,9 +8,11 @@\n #include <cros-camera/cros_camera_hal.h>\n \n #include \"../camera_hal_manager.h\"\n+#include \"../cros_mojo_token.h\"\n \n-static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token)\n+static void set_up(cros::CameraMojoChannelManagerToken *token)\n {\n+\tgCrosMojoToken = token;\n }\n \n static void tear_down()\ndiff --git a/src/android/cros_mojo_token.h b/src/android/cros_mojo_token.h\nnew file mode 100644\nindex 00000000..043c752a\n--- /dev/null\n+++ b/src/android/cros_mojo_token.h\n@@ -0,0 +1,12 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Google Inc.\n+ *\n+ * cros_mojo_token.h - cros-specific mojo token\n+ */\n+\n+#pragma once\n+\n+#include <cros-camera/cros_camera_hal.h>\n+\n+inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr;\ndiff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp\nnew file mode 100644\nindex 00000000..7880a6bd\n--- /dev/null\n+++ b/src/android/jpeg/encoder_jea.cpp\n@@ -0,0 +1,56 @@\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/internal/mapped_framebuffer.h\"\n+\n+#include <cros-camera/camera_mojo_channel_manager_token.h>\n+\n+#include \"../cros_mojo_token.h\"\n+#include \"../hal_framebuffer.h\"\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 (jpegCompressor_)\n+\t\treturn 0;\n+\n+\tif (gCrosMojoToken == nullptr)\n+\t\treturn -ENOTSUP;\n+\n+\tjpegCompressor_ = cros::JpegCompressor::GetInstance(gCrosMojoToken);\n+\n+\treturn 0;\n+}\n+\n+int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *buffer,\n+\t\t       libcamera::Span<const uint8_t> exifData,\n+\t\t       unsigned int quality)\n+{\n+\tif (!jpegCompressor_)\n+\t\treturn -ENOTSUP;\n+\n+\tuint32_t outDataSize = 0;\n+\tconst HALFrameBuffer *fb =\n+\t\tdynamic_cast<const HALFrameBuffer *>(buffer->srcBuffer);\n+\n+\tif (!jpegCompressor_->CompressImageFromHandle(fb->handle(),\n+\t\t\t\t\t\t      *buffer->camera3Buffer,\n+\t\t\t\t\t\t      size_.width, size_.height,\n+\t\t\t\t\t\t      quality, exifData.data(),\n+\t\t\t\t\t\t      exifData.size(),\n+\t\t\t\t\t\t      &outDataSize))\n+\t\treturn -EBUSY;\n+\n+\treturn outDataSize;\n+}\ndiff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h\nnew file mode 100644\nindex 00000000..ffe9df27\n--- /dev/null\n+++ b/src/android/jpeg/encoder_jea.h\n@@ -0,0 +1,31 @@\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 *buffer,\n+\t\t   libcamera::Span<const uint8_t> exifData,\n+\t\t   unsigned int quality) override;\n+\n+private:\n+\tlibcamera::Size size_;\n+\n+\tstd::unique_ptr<cros::JpegCompressor> jpegCompressor_;\n+};\ndiff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build\nindex 08397a87..9162576b 100644\n--- a/src/android/jpeg/meson.build\n+++ b/src/android/jpeg/meson.build\n@@ -1,8 +1,14 @@\n # SPDX-License-Identifier: CC0-1.0\n \n android_hal_sources += files([\n-    'encoder_libjpeg.cpp',\n     'exif.cpp',\n+    'encoder_libjpeg.cpp',\n+    'thumbnailer.cpp',\n     'post_processor_jpeg.cpp',\n-    'thumbnailer.cpp'\n ])\n+\n+platform = get_option('android_platform')\n+if platform == 'cros'\n+    android_hal_sources += files(['encoder_jea.cpp'])\n+    android_deps += [dependency('libcros_camera')]\n+endif\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex 3e676eb4..40261652 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -12,7 +12,11 @@\n #include \"../camera_device.h\"\n #include \"../camera_metadata.h\"\n #include \"../camera_request.h\"\n+#if defined(OS_CHROMEOS)\n+#include \"encoder_jea.h\"\n+#else /* !defined(OS_CHROMEOS) */\n #include \"encoder_libjpeg.h\"\n+#endif\n #include \"exif.h\"\n \n #include <libcamera/base/log.h>\n@@ -46,7 +50,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,\n \n \tthumbnailer_.configure(inCfg.size, inCfg.pixelFormat);\n \n+#if defined(OS_CHROMEOS)\n+\tencoder_ = std::make_unique<EncoderJea>();\n+#else /* !defined(OS_CHROMEOS) */\n \tencoder_ = std::make_unique<EncoderLibJpeg>();\n+#endif\n \n \treturn encoder_->configure(inCfg);\n }\n","prefixes":["libcamera-devel","v10","5/5"]}