From patchwork Wed Jul 20 09:58:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 16700 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 DFC8FBE173 for ; Wed, 20 Jul 2022 09:58:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D89763316; Wed, 20 Jul 2022 11:58:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658311103; bh=10qIGkrWGC1gxcOvfjcET0GQtXkTA1cVJp4+OO+Q6lY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=1lJpljLXWuh9wLzT7iPZobtFm/Uj7TyimTyhZpaq/uJO5jFhnN5SHcfgMUeYN80Xy lYxw8G5L9ntB6WgA7BA3JbhdRUUSX51UAGrqlgO11xvZ39DDdia/rRnHA9hh2vIi5A gxQHJfW6T7nqhHXdR7yEmgmpkzu18d9udp3OgePT7HE1TQnkq/XIvaD4xe1DIMI8KN lWWr37KvAVHUq6ty0fXuNjs0HpnmVsY98LL47j8XsAFY7u0u8ujfAEKweiVzn9gb39 6LCwYTKQ53irjzjT/pLeuH6IT86dL43rPJZq6HuN4Otyr5NK1cl9/4oFxxUmZAk5lG +VxuzF8jMl+AA== Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 795EE63310 for ; Wed, 20 Jul 2022 11:58:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QoZkV49l"; dkim-atps=neutral Received: by mail-pj1-x1033.google.com with SMTP id b7-20020a17090a12c700b001f20eb82a08so1547463pjg.3 for ; Wed, 20 Jul 2022 02:58:21 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=mimkFygxlQjPPEh/hXQokzJDvoQqeIE1rKy7bKu0itA=; b=QoZkV49lNaHsI+ptTv2839H9k7qrdorbXstG+FZ5L2q1zSCdh6j97HiZEIE2gZIxxQ tqG4AJbeAsYzE/r0dl3lxpf0UKX8ZlTmT0MtntzdIC4LtbnVDw33HklcdFqb4NP+6PCC 4AWsQwEX2FAYAw/mnCQR3cWO+xW0N4RFz+4aI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mimkFygxlQjPPEh/hXQokzJDvoQqeIE1rKy7bKu0itA=; b=6aet5qByoLKbvlSzHkSUCp2qldkU8t8Afr3H39P7lA2AVnkPNRspJKLWJDXnQgF1WU cbfJQDBRvH2ph9G0f4RvxpJEfMKTLgHA3TRvAGTYCqteGV2hhp7fO/xPggq1+MlOUEgP 9lrlTEn5qMu05c4KNMfoWnuuA4qNi2cMNJ0hF5o1Swzv7zuGxk6uzUhErMF2dyo1ihzD bUsfdwAGsON1z1sIdzP4s0xkPwDWqDCx3FYZR0toTPZtzaixFG3MHdejyF9HkM+zb9XJ /zZobN30pbxGz4QkUIMi9gfMTH0+5e+VU4wh81rID8EoSRPs3X3KaxO5UmqDbDSJVorC kXbA== X-Gm-Message-State: AJIora8+EVuxibSPg8tkFF3kxxbrbi/hwTTTiSldK8OSmhZu/yokm40B /TVNspAcn12zRlvdueEOzM9rOfqTGjNNfA== X-Google-Smtp-Source: AGRyM1sL2i/aksKAfHp9pPLyLWYiAidF54ndPEM/Bv+vtdndmQ0y1tk6XQ7tpB73c6Ubg19PsNSl5g== X-Received: by 2002:a17:902:cecf:b0:16c:4a62:62ab with SMTP id d15-20020a170902cecf00b0016c4a6262abmr38768654plg.129.1658311099295; Wed, 20 Jul 2022 02:58:19 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (208.158.221.35.bc.googleusercontent.com. [35.221.158.208]) by smtp.gmail.com with ESMTPSA id h15-20020a170902680f00b0016bdeb58611sm13312418plk.112.2022.07.20.02.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 02:58:18 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jul 2022 09:58:12 +0000 Message-Id: <20220720095812.2380218-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220720095812.2380218-1-chenghaoyang@google.com> References: <20220720095812.2380218-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/1] Fix Android adaptor thumbnail buffer lifetime 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: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously the thumbnail buffer is destructed before even being used in Exif. This patch moves the buffer into class Exif, so that the developer won't need to worry about its lifetime. Signed-off-by: Harvey Yang Reviewed-by: Umang Jain --- src/android/jpeg/exif.cpp | 10 ++++++---- src/android/jpeg/exif.h | 10 ++++++++-- src/android/jpeg/post_processor_jpeg.cpp | 6 ++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 3220b458..584a29d0 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -435,11 +435,13 @@ void Exif::setOrientation(int orientation) * Failing to do so, might result in no thumbnail data being set even after a * call to Exif::setThumbnail(). */ -void Exif::setThumbnail(Span thumbnail, - Compression compression) +void Exif::setThumbnail(Compression compression) { - data_->data = const_cast(thumbnail.data()); - data_->size = thumbnail.size(); + if (thumbnail_raw_.empty()) + return; + + data_->data = const_cast(thumbnail_raw_.data()); + data_->size = thumbnail_raw_.size(); setShort(EXIF_IFD_0, EXIF_TAG_COMPRESSION, compression); } diff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h index 2ff8fb78..4784496b 100644 --- a/src/android/jpeg/exif.h +++ b/src/android/jpeg/exif.h @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -60,8 +61,7 @@ public: void setOrientation(int orientation); void setSize(const libcamera::Size &size); - void setThumbnail(libcamera::Span thumbnail, - Compression compression); + void setThumbnail(Compression compression); void setTimestamp(time_t timestamp, std::chrono::milliseconds msec); void setGPSDateTimestamp(time_t timestamp); @@ -78,6 +78,10 @@ public: libcamera::Span data() const { return { exifData_, size_ }; } [[nodiscard]] int generate(); + std::vector& getThumbnailRaw() { + return thumbnail_raw_; + } + private: ExifEntry *createEntry(ExifIfd ifd, ExifTag tag); ExifEntry *createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format, @@ -106,4 +110,6 @@ private: unsigned char *exifData_; unsigned int size_; + + std::vector thumbnail_raw_; }; diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index d72ebc3c..506b00b9 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -163,10 +163,8 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu resultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_QUALITY, quality); if (thumbnailSize != Size(0, 0)) { - std::vector thumbnail; - generateThumbnail(source, thumbnailSize, quality, &thumbnail); - if (!thumbnail.empty()) - exif.setThumbnail(thumbnail, Exif::Compression::JPEG); + generateThumbnail(source, thumbnailSize, quality, &exif.getThumbnailRaw()); + exif.setThumbnail(Exif::Compression::JPEG); } resultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_SIZE, data, 2);