From patchwork Mon Oct 19 08:03:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10091 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6BAE5BDB1F for ; Mon, 19 Oct 2020 08:03:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D87E561161; Mon, 19 Oct 2020 10:03:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dulcV0z3"; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 986EE603AF for ; Mon, 19 Oct 2020 10:03:35 +0200 (CEST) Received: by mail-pg1-x541.google.com with SMTP id n9so5553716pgf.9 for ; Mon, 19 Oct 2020 01:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8L1ugKInDx+d87eaT2HA2bMi3sxRyIb/ajUMJu3cNcc=; b=dulcV0z3ZscV2nfM6f8onhSixUpVY6FiD07fNvA/7SG8qEEhKNQvwv6sZIQo6eo78N k/Qzu64SZpvYJF7syV3rx5SjgXI+OM8VM0b1PmvOJLFAKMKtSoaEt6Tqiv77uwkeiXx2 wacG8EppJP5mTGuaxDT3g9nsInT3CJ99PWF4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8L1ugKInDx+d87eaT2HA2bMi3sxRyIb/ajUMJu3cNcc=; b=Zn4t2LP4h8TV2dkJV+t2FDpEVzkGSi2T5K30PccXV1zW8MqW5uwmN2K+Yr/KsSvKYE NFTmoUVSwYULwen7lLzInXsvejZsoEOWqgMPd9+RyhRTtPCmhLXbepm6uAwtvtOMiZR1 Mcae95OkVEJzGhbJ7BBBTmfO+egsz/wW6/997OVgTB/tvY+E343Mwtj9jJL9qBNCqYCm vmyqY7J1hmu3hcZ0jey1ydbQ+8xQdMJPZsAbNMfyzboiRzxIonrnlXrYC6zFt9lIuBAq v860ioqjaKKEI7jiMGyDA2lep9ahWRAakmK0ckjmj6lb2Q9itiezW8MbX6P/YRAHGp7N MqUg== X-Gm-Message-State: AOAM5323MHuB+yBPQmp+CKjBhrqaxhjIKwSR+h3r3LANiWwQ8WkL89sH 1MBWntLIC63mALZW0CGeHFR+nQK2dZaQSA== X-Google-Smtp-Source: ABdhPJx8zaY5pn3HwoP85BMkBXBtanSkn8O6mKJ4wPGZLqBPd0pzvu7PCgjhfnlcLPSwn9Mytwicnw== X-Received: by 2002:a63:5a11:: with SMTP id o17mr12694785pgb.287.1603094613431; Mon, 19 Oct 2020 01:03:33 -0700 (PDT) Received: from hiroh.tok.corp.google.com ([2401:fa00:8f:2:de4a:3eff:fe7d:f78f]) by smtp.gmail.com with ESMTPSA id t20sm10996135pfe.61.2020.10.19.01.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 01:03:32 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Oct 2020 17:03:23 +0900 Message-Id: <20201019080323.2236548-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: Modify PostProcessor interface X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This modifies PostProcessor interface and polishes the code around the PostProcessor. Signed-off-by: Hirokazu Honda --- src/android/camera_stream.cpp | 9 ++++----- src/android/camera_stream.h | 8 ++++---- src/android/jpeg/encoder.h | 6 +++--- src/android/jpeg/encoder_libjpeg.cpp | 6 +++--- src/android/jpeg/encoder_libjpeg.h | 4 ++-- src/android/jpeg/post_processor_jpeg.cpp | 8 +++++--- src/android/jpeg/post_processor_jpeg.h | 6 +++--- src/android/post_processor.h | 4 ++-- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 1b8afa8..cc8691d 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -40,11 +40,10 @@ LOG_DECLARE_CATEGORY(HAL); CameraStream::CameraStream(CameraDevice *cameraDevice, Type type, camera3_stream_t *camera3Stream, unsigned int index) - : cameraDevice_(cameraDevice), type_(type), + : cameraDevice_(cameraDevice), + config_(cameraDevice_->cameraConfiguration()), type_(type), camera3Stream_(camera3Stream), index_(index) { - config_ = cameraDevice_->cameraConfiguration(); - if (type_ == Type::Internal || type_ == Type::Mapped) { /* * \todo There might be multiple post-processors. The logic @@ -52,7 +51,7 @@ CameraStream::CameraStream(CameraDevice *cameraDevice, Type type, * future. For now, we only have PostProcessorJpeg and that * is what we instantiate here. */ - postProcessor_ = std::make_unique(cameraDevice_); + postProcessor_ = std::make_unique(cameraDevice); } if (type == Type::Internal) { @@ -102,7 +101,7 @@ int CameraStream::process(const libcamera::FrameBuffer &source, if (!postProcessor_) return 0; - return postProcessor_->process(&source, dest->maps()[0], metadata); + return postProcessor_->process(source, dest->maps()[0], metadata); } FrameBuffer *CameraStream::getBuffer() diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index c367a5f..24e66bb 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -124,11 +124,11 @@ public: void putBuffer(libcamera::FrameBuffer *buffer); private: - CameraDevice *cameraDevice_; - libcamera::CameraConfiguration *config_; - Type type_; + CameraDevice const *cameraDevice_; + const libcamera::CameraConfiguration *config_; + const Type type_; camera3_stream_t *camera3Stream_; - unsigned int index_; + const unsigned int index_; std::unique_ptr allocator_; std::vector buffers_; diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index 4483153..270ea60 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -14,11 +14,11 @@ class Encoder { public: - virtual ~Encoder() {}; + virtual ~Encoder() {} virtual int configure(const libcamera::StreamConfiguration &cfg) = 0; - virtual int encode(const libcamera::FrameBuffer *source, - const libcamera::Span &destination, + virtual int encode(const libcamera::FrameBuffer &source, + libcamera::Span destination, const libcamera::Span &exifData) = 0; }; diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index 8995ba5..4236c9d 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -179,11 +179,11 @@ void EncoderLibJpeg::compressNV(const libcamera::MappedBuffer *frame) } } -int EncoderLibJpeg::encode(const FrameBuffer *source, - const libcamera::Span &dest, +int EncoderLibJpeg::encode(const FrameBuffer &source, + libcamera::Span dest, const libcamera::Span &exifData) { - MappedFrameBuffer frame(source, PROT_READ); + MappedFrameBuffer frame(&source, PROT_READ); if (!frame.isValid()) { LOG(JPEG, Error) << "Failed to map FrameBuffer : " << strerror(frame.error()); diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 934caef..391a53c 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -21,8 +21,8 @@ public: ~EncoderLibJpeg(); int configure(const libcamera::StreamConfiguration &cfg) override; - int encode(const libcamera::FrameBuffer *source, - const libcamera::Span &destination, + int encode(const libcamera::FrameBuffer &source, + libcamera::Span destination, const libcamera::Span &exifData) override; private: diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 753c28e..4ded3e3 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -44,8 +44,8 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg, return encoder_->configure(inCfg); } -int PostProcessorJpeg::process(const libcamera::FrameBuffer *source, - const libcamera::Span &destination, +int PostProcessorJpeg::process(const libcamera::FrameBuffer &source, + libcamera::Span destination, CameraMetadata *metadata) { if (!encoder_) @@ -64,8 +64,10 @@ int PostProcessorJpeg::process(const libcamera::FrameBuffer *source, * second, it is good enough. */ exif.setTimestamp(std::time(nullptr)); - if (exif.generate() != 0) + if (exif.generate() != 0) { LOG(JPEG, Error) << "Failed to generate valid EXIF data"; + return -EINVAL; + } int jpeg_size = encoder_->encode(source, destination, exif.data()); if (jpeg_size < 0) { diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h index 62c8650..4d8edf5 100644 --- a/src/android/jpeg/post_processor_jpeg.h +++ b/src/android/jpeg/post_processor_jpeg.h @@ -23,12 +23,12 @@ public: int configure(const libcamera::StreamConfiguration &incfg, const libcamera::StreamConfiguration &outcfg) override; - int process(const libcamera::FrameBuffer *source, - const libcamera::Span &destination, + int process(const libcamera::FrameBuffer &source, + libcamera::Span destination, CameraMetadata *metadata) override; private: - CameraDevice *cameraDevice_; + CameraDevice const *cameraDevice_; std::unique_ptr encoder_; libcamera::Size streamSize_; }; diff --git a/src/android/post_processor.h b/src/android/post_processor.h index a891c43..5f87a5d 100644 --- a/src/android/post_processor.h +++ b/src/android/post_processor.h @@ -20,8 +20,8 @@ public: virtual int configure(const libcamera::StreamConfiguration &inCfg, const libcamera::StreamConfiguration &outCfg) = 0; - virtual int process(const libcamera::FrameBuffer *source, - const libcamera::Span &destination, + virtual int process(const libcamera::FrameBuffer &source, + libcamera::Span destination, CameraMetadata *metadata) = 0; };