From patchwork Fri Jul 22 07:06:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16730 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 93028BE173 for ; Fri, 22 Jul 2022 07:06:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A7F463316; Fri, 22 Jul 2022 09:06:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658473573; bh=uTkJjKLyCGBRwLxl90OBLJclYUGohYZrWKSBG7LOQ/g=; 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=rgiPjOuAwnx+qMNJaJOzU9xj7vmkmZs3usB7WHbCexJ708vYZKIDaFh6OtGd/yU2l GtM5OoJu5K2pkC77ewztDdTEOqGCXV0LInbEnd/Lqwr6CxLBkB6JoEJdtQXvaZws9s LOo82YXsfkSk/ytlCkiJ50bKkyYeYZqt3LN/0aUCGr157WH165cW0J7HIGIy7DPkU+ a0lbrKKvIu54ImxiuRPqbOFqKEHBKmsUMYgLrgjhhrN3alyCPqoOG4A1d+JuFzCDM2 PnX56K4Vrw5z0soAOOKMOnJBr/GfajjZ/LZfKE6J1PsCokinH/4H9ax+V+aYF1ooNS 7BI9W9s1/iPFw== Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 12E7563314 for ; Fri, 22 Jul 2022 09:06:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Tu5izpkL"; dkim-atps=neutral Received: by mail-pj1-x1036.google.com with SMTP id f3-20020a17090ac28300b001f22d62bfbcso2947945pjt.0 for ; Fri, 22 Jul 2022 00:06:10 -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=hDzaxcpCSe7hnLy8+MtAtKRsCENOi94QnmmHgCqkDXQ=; b=Tu5izpkLTLgFz4GkmQuyQrMNBElBlCnCjEz0pt1MxgEP8nfHEG6IHHUw2yod9X2G3M z3T3tZRzzjop12HWDPXt+g5rX/wB5owIKPzcTJ+8CqCP9NokKMQ1ICJRJqlx/ughByb5 Wz8VRYZkvzz8zNofmLVx6Wa6xYKK+UYc3RUOc= 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=hDzaxcpCSe7hnLy8+MtAtKRsCENOi94QnmmHgCqkDXQ=; b=wMDndqv3j2a6lL60Re1r1bOdvh8IaTENwNo5i+8p3V5s20BhtZcTNtB7IxDGnYmMy8 xS0gx74VW4BycE0k+sck8HHjefQg4mcutBkiMzcBKqAlbpniedpwXOUyPb8F9WmtndxR SJQIABXM7Ru7vWjQ/7rlj/wZJ9KuOoqRVjUe1svbJ06UnKHbGhCj/zFs1FeXb4oYaIqF 7dNOeyteJOBB7buGxh19qdapVN6Yv+fKc/5y3aLKxmBSo0+8Gz5QaHKa8rLHmivMGjl4 ejZOOLMznNJzXun3LOxcJPPjnwl/1t9BJcBvYTxQMbdqObzIEr4M6wb1kAbtFAndl1pZ nh8w== X-Gm-Message-State: AJIora8LSDa4N2+gWfhLoFbxj1I+g1DcIqIc/b6/PiOUnkykSo2vYJZM 0pLtTNATYP9jWBXJrceKAJoRg2O3rpWe5Aq0 X-Google-Smtp-Source: AGRyM1sTg9sgU2PQkhHCF9htSHKkRco5fVtMXDKju6/O8lEefEkLQDDghImzfQ8bvRvic7jrLkpLcg== X-Received: by 2002:a17:90b:1bc1:b0:1f0:3830:8c99 with SMTP id oa1-20020a17090b1bc100b001f038308c99mr15975282pjb.1.1658473569039; Fri, 22 Jul 2022 00:06:09 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (231.137.80.34.bc.googleusercontent.com. [34.80.137.231]) by smtp.gmail.com with ESMTPSA id gb17-20020a17090b061100b001f1694dafb1sm2550114pjb.44.2022.07.22.00.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 00:06:07 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jul 2022 07:06:00 +0000 Message-Id: <20220722070600.2949278-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog In-Reply-To: <20220722070600.2949278-1-chenghaoyang@google.com> References: <20220722070600.2949278-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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: Harvey 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: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/jpeg/exif.cpp | 13 +++++-------- src/android/jpeg/exif.h | 5 ++++- src/android/jpeg/post_processor_jpeg.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 3220b458..6b1d0f1f 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -430,16 +430,13 @@ void Exif::setOrientation(int orientation) setShort(EXIF_IFD_0, EXIF_TAG_ORIENTATION, value); } -/* - * The thumbnail data should remain valid until the Exif object is destroyed. - * Failing to do so, might result in no thumbnail data being set even after a - * call to Exif::setThumbnail(). - */ -void Exif::setThumbnail(Span thumbnail, +void Exif::setThumbnail(std::vector &&thumbnail, Compression compression) { - data_->data = const_cast(thumbnail.data()); - data_->size = thumbnail.size(); + thumbnailData_ = std::move(thumbnail); + + data_->data = thumbnailData_.data(); + data_->size = thumbnailData_.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..e68716f3 100644 --- a/src/android/jpeg/exif.h +++ b/src/android/jpeg/exif.h @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -60,7 +61,7 @@ public: void setOrientation(int orientation); void setSize(const libcamera::Size &size); - void setThumbnail(libcamera::Span thumbnail, + void setThumbnail(std::vector &&thumbnail, Compression compression); void setTimestamp(time_t timestamp, std::chrono::milliseconds msec); @@ -106,4 +107,6 @@ private: unsigned char *exifData_; unsigned int size_; + + std::vector thumbnailData_; }; diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index d72ebc3c..0cf56716 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -166,7 +166,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu std::vector thumbnail; generateThumbnail(source, thumbnailSize, quality, &thumbnail); if (!thumbnail.empty()) - exif.setThumbnail(thumbnail, Exif::Compression::JPEG); + exif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG); } resultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_SIZE, data, 2);