{"id":17091,"url":"https://patchwork.libcamera.org/api/1.1/patches/17091/?format=json","web_url":"https://patchwork.libcamera.org/patch/17091/","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":"<20220812090838.1784703-6-hanlinchen@chromium.org>","date":"2022-08-12T09:08:36","name":"[libcamera-devel,v2,5/7] android: Add JpegExifMetadata to store tags setting into Exif","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"26f264d25518ddcf4e07ca37993866a632a86609","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/1.1/people/98/?format=json","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17091/mbox/","series":[{"id":3408,"url":"https://patchwork.libcamera.org/api/1.1/series/3408/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3408","date":"2022-08-12T09:08:31","name":"Implement Android Partial Result Featrue","version":2,"mbox":"https://patchwork.libcamera.org/series/3408/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17091/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17091/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 50F70C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Aug 2022 09:09:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 18F0D63337;\n\tFri, 12 Aug 2022 11:09:00 +0200 (CEST)","from mail-pg1-x532.google.com (mail-pg1-x532.google.com\n\t[IPv6:2607:f8b0:4864:20::532])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C99763326\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 11:08:58 +0200 (CEST)","by mail-pg1-x532.google.com with SMTP id d71so304692pgc.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 02:08:58 -0700 (PDT)","from localhost ([2401:fa00:1:17:1705:d284:d114:2e24])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tx2-20020a17090300c200b0016ee708350bsm1179295plc.14.2022.08.12.02.08.55\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 12 Aug 2022 02:08:56 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660295340;\n\tbh=XusJXHRCLyfE1WSbCkM9zjB4yGYxgU0pXE2ifq9VIcQ=;\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:\n\tFrom;\n\tb=pBvJzsJGmNYSgdKbnQRDoeKprhqU3fQeV875ElZoUEW5qVmbPOTfVuatVL5PCaj0Z\n\tsKuzhDtKua7xayvDViZy72gHTBeB+eVhQSHU13+O+7CHiZGbztvnVJS5s/XvufL7sH\n\tzwEmjSKKzRsDNCDUi0XoYUx8DA7eEwYs5/cEJzgTVX1Nlg2BofD4vJOO3jB/fQE+GO\n\tXDPymn5azHSoii2tTWO6Sb3YM89OmAX73n+hRY9oXebMhMPsarcXQ3TjitKI1udngj\n\trzt4/oKuVp9KD4xFWSmmkS3RG+YCIDDu669fNPrG3bfzeNWQaT5zH5b9qVksd+1znK\n\t1s5EnXTcT7TXw==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=JfN4WG4RHWr9fhXxcCB7SBeaeQU7DHKgKdxX9Hwe+ZY=;\n\tb=lKRrpvwFJg154QPlJbJiPsvKsWMUh6S/cNozUmfQWzoVA1d2Um2yx6UKIKf+nU0pNq\n\tQ3iaAdjREeQVb3qn5bptkbvnupq44mxce+hCwsyZC8PI4AX4FIriVaPDZt1oJv7uB6S3\n\tMd8n0IzD6sNdgbmo5lhYoEKX3ZSD+D8gLCRn0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"lKRrpvwF\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=JfN4WG4RHWr9fhXxcCB7SBeaeQU7DHKgKdxX9Hwe+ZY=;\n\tb=MGbMYU+QOOjicGPbuJRCtjhN/4FJaATkbnBTtRVxBglFcT8+dI0ktsE87XkxZl/WUN\n\tMb3ejSJtW0dXv1fy8JPdY25b2opGceavh1iVPpIsL0xrLV3QlHll8uf1JZfKJtfpambT\n\t/AJrirFMXSQOZVU3tiC7svSJ+yKPDfXswNgk04vXoNqFoPGucIIAuL6yEBV1qDClUApl\n\tBCo+w8FJ0q7xA7B0PgxoOlLEFmYOmWKtes90BAjpgBQyrb2D04vNPm8bUeR39jwZmwNt\n\tBq14o9lT78oxC/1MyGjN0Kjhb9UsZ+xNHLNLzfcjk9dAiSSgH17FnkKITS/NCWpqBBUH\n\tqdfw==","X-Gm-Message-State":"ACgBeo1kZBGgLwhDbNQg+wqZYKr7bxtzOyS3MAugSOSsHdMX3TtR3Xw1\n\tTCUKkVb+34UkmOxsF5gqbtcEYw4emleNtA==","X-Google-Smtp-Source":"AA6agR57M+Tn61CvEHN8SmE/j4WPxCzlXkE3/yNYrK32ZMN/9yoQ1jclKTFnBxfPJhzfkIDcbicHtA==","X-Received":"by 2002:a65:5941:0:b0:41d:a203:c043 with SMTP id\n\tg1-20020a655941000000b0041da203c043mr2315382pgu.483.1660295336747; \n\tFri, 12 Aug 2022 02:08:56 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 12 Aug 2022 17:08:36 +0800","Message-Id":"<20220812090838.1784703-6-hanlinchen@chromium.org>","X-Mailer":"git-send-email 2.37.1.595.g718a3a8f04-goog","In-Reply-To":"<20220812090838.1784703-1-hanlinchen@chromium.org>","References":"<20220812090838.1784703-1-hanlinchen@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 5/7] android: Add JpegExifMetadata to\n\tstore tags setting into Exif","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":"Han-Lin Chen via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Han-Lin Chen <hanlinchen@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"With partial result, some metadata needed to adding into Exif may be sent\nback to framework earlier before Jpeg post-processing. Add a type\nJpegExifMetadata associated with StreamBuffer to store the values, so Jpeg\npost-processing doesn't need to reference to current metadata for the them.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n src/android/camera_device.cpp            | 27 ++++++++++++++++++++++++\n src/android/camera_device.h              |  2 ++\n src/android/camera_request.h             |  6 ++++++\n src/android/camera_stream.h              |  4 ++++\n src/android/jpeg/post_processor_jpeg.cpp | 13 ++++++------\n 5 files changed, 46 insertions(+), 6 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 0248f146..a14d5de9 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -1221,6 +1221,10 @@ void CameraDevice::requestComplete(Request *request)\n \t\tCameraStream *stream = iter->first;\n \t\tStreamBuffer *buffer = iter->second;\n \n+\t\tif (stream->isJpegStream()) {\n+\t\t\tgenerateJpegExifMetadata(descriptor, buffer);\n+\t\t}\n+\n \t\tFrameBuffer *src = request->findBuffer(stream->stream());\n \t\tif (!src) {\n \t\t\tLOG(HAL, Error) << \"Failed to find a source stream buffer\";\n@@ -1410,6 +1414,29 @@ void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream,\n \tcallbacks_->notify(callbacks_, &notify);\n }\n \n+/*\n+ * Set jpeg metadata used to generate EXIF in the JPEG post processing.\n+ */\n+void CameraDevice::generateJpegExifMetadata(Camera3RequestDescriptor *request,\n+\t\t\t\t\t    StreamBuffer *buffer) const\n+{\n+\tconst ControlList &metadata = request->request_->metadata();\n+\tauto &jpegExifMetadata = buffer->jpegExifMetadata;\n+\tjpegExifMetadata.emplace(StreamBuffer::JpegExifMetadata());\n+\n+\tjpegExifMetadata->sensorExposureTime = 0;\n+\tif (metadata.contains(controls::ExposureTime)) {\n+\t\tjpegExifMetadata->sensorExposureTime = metadata.get(controls::ExposureTime) * 1000ULL;\n+\t}\n+\n+\t/*\n+\t * todo: Android Sensitivity = analog gain X digital gain only on sensor.\n+\t * Digital gain on ISP shouldn't be included. Calculate sensitivity\n+\t * accordingingly when we can differentiate the source of digital gains.\n+\t */\n+\tjpegExifMetadata->sensorSensitivityISO = 100;\n+}\n+\n /*\n  * Produce a set of fixed result metadata.\n  */\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 9eb7221b..7b279895 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -97,6 +97,8 @@ private:\n \t\tLIBCAMERA_TSA_EXCLUDES(descriptorsMutex_);\n \tvoid sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_);\n \tvoid setBufferStatus(StreamBuffer &buffer, StreamBuffer::Status status);\n+\tvoid generateJpegExifMetadata(Camera3RequestDescriptor *request,\n+\t\t\t\t      StreamBuffer *buffer) const;\n \tstd::unique_ptr<CameraMetadata> getResultMetadata(\n \t\tconst Camera3RequestDescriptor &descriptor) const;\n \ndiff --git a/src/android/camera_request.h b/src/android/camera_request.h\nindex 5aa4eea8..f91de955 100644\n--- a/src/android/camera_request.h\n+++ b/src/android/camera_request.h\n@@ -42,6 +42,11 @@ public:\n \tStreamBuffer(StreamBuffer &&);\n \tStreamBuffer &operator=(StreamBuffer &&);\n \n+\tstruct JpegExifMetadata {\n+\t\tint64_t sensorExposureTime;\n+\t\tint32_t sensorSensitivityISO;\n+\t};\n+\n \tCameraStream *stream;\n \tbuffer_handle_t *camera3Buffer;\n \tstd::unique_ptr<libcamera::FrameBuffer> frameBuffer;\n@@ -50,6 +55,7 @@ public:\n \tlibcamera::FrameBuffer *internalBuffer = nullptr;\n \tconst libcamera::FrameBuffer *srcBuffer = nullptr;\n \tstd::unique_ptr<CameraBuffer> dstBuffer;\n+\tstd::optional<JpegExifMetadata> jpegExifMetadata;\n \tCamera3RequestDescriptor *request;\n \n private:\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex c3b2e325..fc50d412 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -125,6 +125,10 @@ public:\n \tconst libcamera::StreamConfiguration &configuration() const;\n \tlibcamera::Stream *stream() const;\n \tCameraStream *sourceStream() const { return sourceStream_; }\n+\tbool isJpegStream() const\n+\t{\n+\t\treturn camera3Stream_->format == HAL_PIXEL_FORMAT_BLOB;\n+\t}\n \n \tint configure();\n \tint process(StreamBuffer *streamBuffer);\ndiff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\nindex b9ba38ce..7e3713f5 100644\n--- a/src/android/jpeg/post_processor_jpeg.cpp\n+++ b/src/android/jpeg/post_processor_jpeg.cpp\n@@ -104,8 +104,11 @@ void PostProcessorJpeg::process(StreamBuffer *streamBuffer)\n \n \tconst FrameBuffer &source = *streamBuffer->srcBuffer;\n \tCameraBuffer *destination = streamBuffer->dstBuffer.get();\n+\tconst std::optional<StreamBuffer::JpegExifMetadata> &jpegExifMetadata =\n+\t\tstreamBuffer->jpegExifMetadata;\n \n \tASSERT(destination->numPlanes() == 1);\n+\tASSERT(jpegExifMetadata.has_value());\n \n \tconst CameraMetadata &requestMetadata = streamBuffer->request->settings_;\n \tCameraMetadata *resultMetadata = streamBuffer->request->resultMetadata_.get();\n@@ -131,15 +134,13 @@ void PostProcessorJpeg::process(StreamBuffer *streamBuffer)\n \t */\n \texif.setTimestamp(std::time(nullptr), 0ms);\n \n-\tret = resultMetadata->getEntry(ANDROID_SENSOR_EXPOSURE_TIME, &entry);\n-\texif.setExposureTime(ret ? *entry.data.i64 : 0);\n+\texif.setExposureTime(jpegExifMetadata->sensorExposureTime * 1000);\n+\texif.setISO(jpegExifMetadata->sensorSensitivityISO);\n+\n \tret = requestMetadata.getEntry(ANDROID_LENS_APERTURE, &entry);\n \tif (ret)\n \t\texif.setAperture(*entry.data.f);\n \n-\tret = resultMetadata->getEntry(ANDROID_SENSOR_SENSITIVITY, &entry);\n-\texif.setISO(ret ? *entry.data.i32 : 100);\n-\n \texif.setFlash(Exif::Flash::FlashNotPresent);\n \texif.setWhiteBalance(Exif::WhiteBalance::Auto);\n \n@@ -152,6 +153,7 @@ void PostProcessorJpeg::process(StreamBuffer *streamBuffer)\n \t\t\t\t\t *entry.data.i64);\n \t}\n \n+\tstd::vector<unsigned char> thumbnail;\n \tret = requestMetadata.getEntry(ANDROID_JPEG_THUMBNAIL_SIZE, &entry);\n \tif (ret) {\n \t\tconst int32_t *data = entry.data.i32;\n@@ -163,7 +165,6 @@ void PostProcessorJpeg::process(StreamBuffer *streamBuffer)\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","prefixes":["libcamera-devel","v2","5/7"]}