Patch Detail
Show a patch.
GET /api/1.1/patches/18123/?format=api
{ "id": 18123, "url": "https://patchwork.libcamera.org/api/1.1/patches/18123/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18123/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230116002808.16014-7-laurent.pinchart@ideasonboard.com>", "date": "2023-01-16T00:28:06", "name": "[libcamera-devel,v9,6/8] android: jpeg: Return an error code from generateThumbnail()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6d0ae90c5ba5be23a0c3a7cddd4da9d5082fdc8e", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18123/mbox/", "series": [ { "id": 3712, "url": "https://patchwork.libcamera.org/api/1.1/series/3712/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3712", "date": "2023-01-16T00:28:00", "name": "Add CrOS JEA implementation", "version": 9, "mbox": "https://patchwork.libcamera.org/series/3712/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18123/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18123/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 9DE8AC3294\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Jan 2023 00:28:18 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51B6B625FE;\n\tMon, 16 Jan 2023 01:28:18 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 389FC625F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Jan 2023 01:28:17 +0100 (CET)", "from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BCA3B9B4;\n\tMon, 16 Jan 2023 01:28:16 +0100 (CET)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673828898;\n\tbh=ljLKoyiQEj8/kbVr0ywJOLhgZoHqygtWF9far7AI1QQ=;\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=aSl9pMbpqQsDKopA2BxPHXGmwhjL80Jzm6HiOegr344/DqDP+uQmGqVyD99spqyjD\n\tStqMT5xfh++UUDQXQWMXq6VV3L5+vpY+rdzvor/UrD4ey+pfstLjHInwTjOdKDir5X\n\tQg6pyOB0IEr2HNDU+sX0saHLFcUzO6PPzoC7anuVMND76MWRXzDIsNnpjHxiCC1tiC\n\tU65WaAZ0iQ/8Y+hG/kjwSW4iHRaKJbtNc0RumyvZxibFrM5mJxXk3ioSZAxoGvQLsh\n\t4AKOr2UgPAIK/uEvxuXjxa6dCpSPIiSXhWgK/0Nnis6BVYySuWLXkCFdWwttwNLm83\n\tWfcQbvkNpz0fA==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673828897;\n\tbh=ljLKoyiQEj8/kbVr0ywJOLhgZoHqygtWF9far7AI1QQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=l9j4QxRcbe2FU74lvYMdcxQvfPXRgXixddddYfZND/GU3zEZk/3nN62p24Bi8122+\n\tG3VSSN6VeMsRhKDSDoYgqGoLcGt32MD9Zsu6gHgy+R0zoUvkgn/gFoFzEC9Z9XlbLG\n\tV0IE1mimlyRIeSlI+wCqrVUCFUmk6ZNPrL6+5/+4=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"l9j4QxRc\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 16 Jan 2023 02:28:06 +0200", "Message-Id": "<20230116002808.16014-7-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.38.2", "In-Reply-To": "<20230116002808.16014-1-laurent.pinchart@ideasonboard.com>", "References": "<20230116002808.16014-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v9 6/8] android: jpeg: Return an error\n\tcode from generateThumbnail()", "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": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Cc": "Harvey Yang <chenghaoyang@chromium.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The usual way to signal errors in libcamera is to return an error code.\nChange the Encoder::generateThumbnail() function to return an int\ninstead of signaling errors by not resizing the thumbnail vector. This\nallows propagating error codes to the callers.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/jpeg/encoder.h | 8 +--\n src/android/jpeg/encoder_libjpeg.cpp | 70 +++++++++++++-----------\n src/android/jpeg/encoder_libjpeg.h | 8 +--\n src/android/jpeg/post_processor_jpeg.cpp | 6 +-\n 4 files changed, 48 insertions(+), 44 deletions(-)", "diff": "diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h\nindex 5f9ef890023a..d15f22e67830 100644\n--- a/src/android/jpeg/encoder.h\n+++ b/src/android/jpeg/encoder.h\n@@ -22,8 +22,8 @@ public:\n \t\t\t libcamera::Span<uint8_t> destination,\n \t\t\t libcamera::Span<const uint8_t> exifData,\n \t\t\t unsigned int quality) = 0;\n-\tvirtual void generateThumbnail(const libcamera::FrameBuffer &source,\n-\t\t\t\t const libcamera::Size &targetSize,\n-\t\t\t\t unsigned int quality,\n-\t\t\t\t std::vector<unsigned char> *thumbnail) = 0;\n+\tvirtual int generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t\t const libcamera::Size &targetSize,\n+\t\t\t\t unsigned int quality,\n+\t\t\t\t std::vector<unsigned char> *thumbnail) = 0;\n };\ndiff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex 9bbf1abbe09c..8f4df7899dfd 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -89,53 +89,57 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,\n \treturn captureEncoder_.encode(frame.planes(), dest, exifData, quality);\n }\n \n-void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source,\n-\t\t\t\t const libcamera::Size &targetSize,\n-\t\t\t\t unsigned int quality,\n-\t\t\t\t std::vector<unsigned char> *thumbnail)\n+int EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t\t const libcamera::Size &targetSize,\n+\t\t\t\t unsigned int quality,\n+\t\t\t\t std::vector<unsigned char> *thumbnail)\n {\n \t/* Stores the raw scaled-down thumbnail bytes. */\n \tstd::vector<unsigned char> rawThumbnail;\n \n \tthumbnailer_.createThumbnail(source, targetSize, &rawThumbnail);\n+\tif (rawThumbnail.empty())\n+\t\treturn -EINVAL;\n \n \tStreamConfiguration thCfg;\n \tthCfg.size = targetSize;\n \tthCfg.pixelFormat = thumbnailer_.pixelFormat();\n \tint ret = thumbnailEncoder_.configure(thCfg);\n+\tif (ret)\n+\t\treturn ret;\n \n-\tif (!rawThumbnail.empty() && !ret) {\n-\t\t/*\n-\t\t * \\todo Avoid value-initialization of all elements of the\n-\t\t * vector.\n-\t\t */\n-\t\tthumbnail->resize(rawThumbnail.size());\n+\t/*\n+\t * \\todo Avoid value-initialization of all elements of the\n+\t * vector.\n+\t */\n+\tthumbnail->resize(rawThumbnail.size());\n \n-\t\t/*\n-\t\t * Split planes manually as the encoder expects a vector of\n-\t\t * planes.\n-\t\t *\n-\t\t * \\todo Pass a vector of planes directly to\n-\t\t * Thumbnailer::createThumbnailer above and remove the manual\n-\t\t * planes split from here.\n-\t\t */\n-\t\tstd::vector<Span<uint8_t>> thumbnailPlanes;\n-\t\tconst PixelFormatInfo &formatNV12 =\n-\t\t\tPixelFormatInfo::info(formats::NV12);\n-\t\tsize_t yPlaneSize = formatNV12.planeSize(targetSize, 0);\n-\t\tsize_t uvPlaneSize = formatNV12.planeSize(targetSize, 1);\n-\t\tthumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize });\n-\t\tthumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize,\n-\t\t\t\t\t uvPlaneSize });\n+\t/*\n+\t * Split planes manually as the encoder expects a vector of\n+\t * planes.\n+\t *\n+\t * \\todo Pass a vector of planes directly to\n+\t * Thumbnailer::createThumbnailer above and remove the manual\n+\t * planes split from here.\n+\t */\n+\tstd::vector<Span<uint8_t>> thumbnailPlanes;\n+\tconst PixelFormatInfo &formatNV12 =\n+\t\tPixelFormatInfo::info(formats::NV12);\n+\tsize_t yPlaneSize = formatNV12.planeSize(targetSize, 0);\n+\tsize_t uvPlaneSize = formatNV12.planeSize(targetSize, 1);\n+\tthumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize });\n+\tthumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize,\n+\t\t\t\t uvPlaneSize });\n \n-\t\tint jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail,\n-\t\t\t\t\t\t\t{}, quality);\n-\t\tthumbnail->resize(jpegSize);\n+\tint jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail,\n+\t\t\t\t\t\t{}, quality);\n+\tthumbnail->resize(jpegSize);\n \n-\t\tLOG(JPEG, Debug)\n-\t\t\t<< \"Thumbnail compress returned \"\n-\t\t\t<< jpegSize << \" bytes\";\n-\t}\n+\tLOG(JPEG, Debug)\n+\t\t<< \"Thumbnail compress returned \"\n+\t\t<< jpegSize << \" bytes\";\n+\n+\treturn 0;\n }\n \n EncoderLibJpeg::Encoder::Encoder()\ndiff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h\nindex a022a72e02bf..9cff4f1b42e3 100644\n--- a/src/android/jpeg/encoder_libjpeg.h\n+++ b/src/android/jpeg/encoder_libjpeg.h\n@@ -28,10 +28,10 @@ public:\n \t\t libcamera::Span<uint8_t> destination,\n \t\t libcamera::Span<const uint8_t> exifData,\n \t\t unsigned int quality) override;\n-\tvoid generateThumbnail(const libcamera::FrameBuffer &source,\n-\t\t\t const libcamera::Size &targetSize,\n-\t\t\t unsigned int quality,\n-\t\t\t std::vector<unsigned char> *thumbnail) override;\n+\tint generateThumbnail(const libcamera::FrameBuffer &source,\n+\t\t\t const libcamera::Size &targetSize,\n+\t\t\t unsigned int quality,\n+\t\t\t std::vector<unsigned char> *thumbnail) override;\n \n private:\n \tclass Encoder\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex 69b18a2e5945..5df89383e1af 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -115,9 +115,9 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu\n \n \t\tif (thumbnailSize != Size(0, 0)) {\n \t\t\tstd::vector<unsigned char> thumbnail;\n-\t\t\tencoder_->generateThumbnail(source, thumbnailSize,\n-\t\t\t\t\t\t quality, &thumbnail);\n-\t\t\tif (!thumbnail.empty())\n+\t\t\tret = encoder_->generateThumbnail(source, thumbnailSize,\n+\t\t\t\t\t\t\t quality, &thumbnail);\n+\t\t\tif (!ret)\n \t\t\t\texif.setThumbnail(std::move(thumbnail), Exif::Compression::JPEG);\n \t\t}\n \n", "prefixes": [ "libcamera-devel", "v9", "6/8" ] }