{"id":16700,"url":"https://patchwork.libcamera.org/api/1.1/patches/16700/?format=json","web_url":"https://patchwork.libcamera.org/patch/16700/","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":"<20220720095812.2380218-2-chenghaoyang@google.com>","date":"2022-07-20T09:58:12","name":"[libcamera-devel,v6,1/1] Fix Android adaptor thumbnail buffer lifetime","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"eae7f720986bb422fc1f19a859d9f065c7a54b67","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/16700/mbox/","series":[{"id":3307,"url":"https://patchwork.libcamera.org/api/1.1/series/3307/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3307","date":"2022-07-20T09:58:11","name":"Android adaptor thumbnail buffer lifetime issue","version":6,"mbox":"https://patchwork.libcamera.org/series/3307/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16700/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16700/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 DFC8FBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Jul 2022 09:58:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D89763316;\n\tWed, 20 Jul 2022 11:58:23 +0200 (CEST)","from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com\n\t[IPv6:2607:f8b0:4864:20::1033])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 795EE63310\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Jul 2022 11:58:21 +0200 (CEST)","by mail-pj1-x1033.google.com with SMTP id\n\tb7-20020a17090a12c700b001f20eb82a08so1547463pjg.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Jul 2022 02:58:21 -0700 (PDT)","from chenghaoyang-low.c.googlers.com.com\n\t(208.158.221.35.bc.googleusercontent.com. [35.221.158.208])\n\tby smtp.gmail.com with ESMTPSA id\n\th15-20020a170902680f00b0016bdeb58611sm13312418plk.112.2022.07.20.02.58.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 20 Jul 2022 02:58:18 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658311103;\n\tbh=10qIGkrWGC1gxcOvfjcET0GQtXkTA1cVJp4+OO+Q6lY=;\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=1lJpljLXWuh9wLzT7iPZobtFm/Uj7TyimTyhZpaq/uJO5jFhnN5SHcfgMUeYN80Xy\n\tlYxw8G5L9ntB6WgA7BA3JbhdRUUSX51UAGrqlgO11xvZ39DDdia/rRnHA9hh2vIi5A\n\tgxQHJfW6T7nqhHXdR7yEmgmpkzu18d9udp3OgePT7HE1TQnkq/XIvaD4xe1DIMI8KN\n\tlWWr37KvAVHUq6ty0fXuNjs0HpnmVsY98LL47j8XsAFY7u0u8ujfAEKweiVzn9gb39\n\t6LCwYTKQ53irjzjT/pLeuH6IT86dL43rPJZq6HuN4Otyr5NK1cl9/4oFxxUmZAk5lG\n\t+VxuzF8jMl+AA==","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=mimkFygxlQjPPEh/hXQokzJDvoQqeIE1rKy7bKu0itA=;\n\tb=QoZkV49lNaHsI+ptTv2839H9k7qrdorbXstG+FZ5L2q1zSCdh6j97HiZEIE2gZIxxQ\n\ttqG4AJbeAsYzE/r0dl3lxpf0UKX8ZlTmT0MtntzdIC4LtbnVDw33HklcdFqb4NP+6PCC\n\t4AWsQwEX2FAYAw/mnCQR3cWO+xW0N4RFz+4aI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"QoZkV49l\"; \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=mimkFygxlQjPPEh/hXQokzJDvoQqeIE1rKy7bKu0itA=;\n\tb=6aet5qByoLKbvlSzHkSUCp2qldkU8t8Afr3H39P7lA2AVnkPNRspJKLWJDXnQgF1WU\n\tcbfJQDBRvH2ph9G0f4RvxpJEfMKTLgHA3TRvAGTYCqteGV2hhp7fO/xPggq1+MlOUEgP\n\t9lrlTEn5qMu05c4KNMfoWnuuA4qNi2cMNJ0hF5o1Swzv7zuGxk6uzUhErMF2dyo1ihzD\n\tbUsfdwAGsON1z1sIdzP4s0xkPwDWqDCx3FYZR0toTPZtzaixFG3MHdejyF9HkM+zb9XJ\n\t/zZobN30pbxGz4QkUIMi9gfMTH0+5e+VU4wh81rID8EoSRPs3X3KaxO5UmqDbDSJVorC\n\tkXbA==","X-Gm-Message-State":"AJIora8+EVuxibSPg8tkFF3kxxbrbi/hwTTTiSldK8OSmhZu/yokm40B\n\t/TVNspAcn12zRlvdueEOzM9rOfqTGjNNfA==","X-Google-Smtp-Source":"AGRyM1sL2i/aksKAfHp9pPLyLWYiAidF54ndPEM/Bv+vtdndmQ0y1tk6XQ7tpB73c6Ubg19PsNSl5g==","X-Received":"by 2002:a17:902:cecf:b0:16c:4a62:62ab with SMTP id\n\td15-20020a170902cecf00b0016c4a6262abmr38768654plg.129.1658311099295; \n\tWed, 20 Jul 2022 02:58:19 -0700 (PDT)","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 1/1] Fix Android adaptor thumbnail\n\tbuffer lifetime","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@google.com>,\n\tHarvey Yang <chenghaoyang@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Previously the thumbnail buffer is destructed before even being used in\nExif. This patch moves the buffer into class Exif, so that the developer\nwon't need to worry about its lifetime.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n src/android/jpeg/exif.cpp                | 10 ++++++----\n src/android/jpeg/exif.h                  | 10 ++++++++--\n src/android/jpeg/post_processor_jpeg.cpp |  6 ++----\n 3 files changed, 16 insertions(+), 10 deletions(-)","diff":"diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp\nindex 3220b458..584a29d0 100644\n--- a/src/android/jpeg/exif.cpp\n+++ b/src/android/jpeg/exif.cpp\n@@ -435,11 +435,13 @@ void Exif::setOrientation(int orientation)\n  * Failing to do so, might result in no thumbnail data being set even after a\n  * call to Exif::setThumbnail().\n  */\n-void Exif::setThumbnail(Span<const unsigned char> thumbnail,\n-\t\t\tCompression compression)\n+void Exif::setThumbnail(Compression compression)\n {\n-\tdata_->data = const_cast<unsigned char *>(thumbnail.data());\n-\tdata_->size = thumbnail.size();\n+\tif (thumbnail_raw_.empty())\n+\t\treturn;\n+\n+\tdata_->data = const_cast<unsigned char *>(thumbnail_raw_.data());\n+\tdata_->size = thumbnail_raw_.size();\n \n \tsetShort(EXIF_IFD_0, EXIF_TAG_COMPRESSION, compression);\n }\ndiff --git a/src/android/jpeg/exif.h b/src/android/jpeg/exif.h\nindex 2ff8fb78..4784496b 100644\n--- a/src/android/jpeg/exif.h\n+++ b/src/android/jpeg/exif.h\n@@ -10,6 +10,7 @@\n #include <chrono>\n #include <string>\n #include <time.h>\n+#include <vector>\n \n #include <libexif/exif-data.h>\n \n@@ -60,8 +61,7 @@ public:\n \n \tvoid setOrientation(int orientation);\n \tvoid setSize(const libcamera::Size &size);\n-\tvoid setThumbnail(libcamera::Span<const unsigned char> thumbnail,\n-\t\t\t  Compression compression);\n+\tvoid setThumbnail(Compression compression);\n \tvoid setTimestamp(time_t timestamp, std::chrono::milliseconds msec);\n \n \tvoid setGPSDateTimestamp(time_t timestamp);\n@@ -78,6 +78,10 @@ public:\n \tlibcamera::Span<const uint8_t> data() const { return { exifData_, size_ }; }\n \t[[nodiscard]] int generate();\n \n+\tstd::vector<unsigned char>& getThumbnailRaw() {\n+\t\treturn thumbnail_raw_;\n+\t}\n+\n private:\n \tExifEntry *createEntry(ExifIfd ifd, ExifTag tag);\n \tExifEntry *createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format,\n@@ -106,4 +110,6 @@ private:\n \n \tunsigned char *exifData_;\n \tunsigned int size_;\n+\n+\tstd::vector<unsigned char> thumbnail_raw_;\n };\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex d72ebc3c..506b00b9 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -163,10 +163,8 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu\n \t\tresultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_QUALITY, quality);\n \n \t\tif (thumbnailSize != Size(0, 0)) {\n-\t\t\tstd::vector<unsigned char> thumbnail;\n-\t\t\tgenerateThumbnail(source, thumbnailSize, quality, &thumbnail);\n-\t\t\tif (!thumbnail.empty())\n-\t\t\t\texif.setThumbnail(thumbnail, Exif::Compression::JPEG);\n+\t\t\tgenerateThumbnail(source, thumbnailSize, quality, &exif.getThumbnailRaw());\n+\t\t\texif.setThumbnail(Exif::Compression::JPEG);\n \t\t}\n \n \t\tresultMetadata->addEntry(ANDROID_JPEG_THUMBNAIL_SIZE, data, 2);\n","prefixes":["libcamera-devel","v6","1/1"]}