{"id":23599,"url":"https://patchwork.libcamera.org/api/patches/23599/?format=json","web_url":"https://patchwork.libcamera.org/patch/23599/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20250619082027.4058507-1-chenghaoyang@google.com>","date":"2025-06-19T08:20:17","name":"[v2] EncoderLibJpeg: Migrate const global pixelInfo to static","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c597fa0e4b5cd3c53736d76f9623269c6cc191eb","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23599/mbox/","series":[{"id":5230,"url":"https://patchwork.libcamera.org/api/series/5230/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5230","date":"2025-06-19T08:20:17","name":"[v2] EncoderLibJpeg: Migrate const global pixelInfo to static","version":2,"mbox":"https://patchwork.libcamera.org/series/5230/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23599/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23599/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 D7B82BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Jun 2025 08:20:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D9E668DCD;\n\tThu, 19 Jun 2025 10:20:36 +0200 (CEST)","from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com\n\t[IPv6:2607:f8b0:4864:20::102b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0379761538\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Jun 2025 10:20:33 +0200 (CEST)","by mail-pj1-x102b.google.com with SMTP id\n\t98e67ed59e1d1-311a6236effso301126a91.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Jun 2025 01:20:33 -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\t98e67ed59e1d1-3158a24bc2fsm1526588a91.22.2025.06.19.01.20.31\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 19 Jun 2025 01:20:31 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"QQpoBtDB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1750321232; x=1750926032;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=fUCzg5s08phrQ6T9dtFo1JDLc8L13lmp2iapjNFek6Q=;\n\tb=QQpoBtDBswbfUnKjp/9SmHWjXVrb2G9fWglfjfOZ9me53ZsKeFoXvb5XJb9oBH0lU4\n\tOW2ajJivZU1O26ZRr+vURjUAHDepiOgOEKaup5wkRx01eUo06iNktyV0+uZeh8SqDCcJ\n\tpkCnPn5/h320zeDoFQHxsVGwwKt7ZXyGEmttM=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1750321232; x=1750926032;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date: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source":"AGHT+IEWKLPH2EAwBIDZZEaUO9VGLQ0DuBH3r4UwODMa0BPTxgX1C1ssri/uNcaCFwNefqrVAE7MaQ==","X-Received":"by 2002:a17:90b:1c04:b0:312:f2ee:a895 with SMTP id\n\t98e67ed59e1d1-313f1e1a908mr26451646a91.31.1750321232143; \n\tThu, 19 Jun 2025 01:20:32 -0700 (PDT)","From":"Harvey Yang <chenghaoyang@chromium.org>","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Harvey Yang <chenghaoyang@chromium.org>","Subject":"[PATCH v2] EncoderLibJpeg: Migrate const global pixelInfo to static","Date":"Thu, 19 Jun 2025 08:20:17 +0000","Message-ID":"<20250619082027.4058507-1-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.50.0.rc2.701.gf1e915cc24-goog","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Harvey Yang <chenghaoyang@chromium.org>\n\nPreviously, const global `pixelInfo` in `encoder_libjpeg.cpp` is\ninitialized before const global `pixelFormatInfo` in `formats.cpp`,\neven if `formats.cpp` is wrapped in the base libcamera shared library,\nand the android adapter (which contains `encoder_libjpeg.cpp`)\ndepends on the base libcamera shared library.\n\nThe reason should be that C++ initialization order doesn't follow the\nlinking process.\n\nThis patch migrates const global pixelInfo to static to avoid the race\ncondition.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n src/android/jpeg/encoder_libjpeg.cpp | 28 ++++++++++++++--------------\n 1 file changed, 14 insertions(+), 14 deletions(-)","diff":"diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp\nindex cb242b5ec6a8..3ba5103d5ad5 100644\n--- a/src/android/jpeg/encoder_libjpeg.cpp\n+++ b/src/android/jpeg/encoder_libjpeg.cpp\n@@ -38,26 +38,26 @@ struct JPEGPixelFormatInfo {\n \tbool nvSwap;\n };\n \n-const std::map<PixelFormat, JPEGPixelFormatInfo> pixelInfo{\n-\t{ formats::R8, { JCS_GRAYSCALE, PixelFormatInfo::info(formats::R8), false } },\n-\n-\t{ formats::RGB888, { JCS_EXT_BGR, PixelFormatInfo::info(formats::RGB888), false } },\n-\t{ formats::BGR888, { JCS_EXT_RGB, PixelFormatInfo::info(formats::BGR888), false } },\n-\n-\t{ formats::NV12, { JCS_YCbCr, PixelFormatInfo::info(formats::NV12), false } },\n-\t{ formats::NV21, { JCS_YCbCr, PixelFormatInfo::info(formats::NV21), true } },\n-\t{ formats::NV16, { JCS_YCbCr, PixelFormatInfo::info(formats::NV16), false } },\n-\t{ formats::NV61, { JCS_YCbCr, PixelFormatInfo::info(formats::NV61), true } },\n-\t{ formats::NV24, { JCS_YCbCr, PixelFormatInfo::info(formats::NV24), false } },\n-\t{ formats::NV42, { JCS_YCbCr, PixelFormatInfo::info(formats::NV42), true } },\n-};\n-\n const struct JPEGPixelFormatInfo &findPixelInfo(const PixelFormat &format)\n {\n \tstatic const struct JPEGPixelFormatInfo invalidPixelFormat {\n \t\tJCS_UNKNOWN, PixelFormatInfo(), false\n \t};\n \n+\tstatic const std::map<PixelFormat, JPEGPixelFormatInfo> pixelInfo{\n+\t\t{ formats::R8, { JCS_GRAYSCALE, PixelFormatInfo::info(formats::R8), false } },\n+\n+\t\t{ formats::RGB888, { JCS_EXT_BGR, PixelFormatInfo::info(formats::RGB888), false } },\n+\t\t{ formats::BGR888, { JCS_EXT_RGB, PixelFormatInfo::info(formats::BGR888), false } },\n+\n+\t\t{ formats::NV12, { JCS_YCbCr, PixelFormatInfo::info(formats::NV12), false } },\n+\t\t{ formats::NV21, { JCS_YCbCr, PixelFormatInfo::info(formats::NV21), true } },\n+\t\t{ formats::NV16, { JCS_YCbCr, PixelFormatInfo::info(formats::NV16), false } },\n+\t\t{ formats::NV61, { JCS_YCbCr, PixelFormatInfo::info(formats::NV61), true } },\n+\t\t{ formats::NV24, { JCS_YCbCr, PixelFormatInfo::info(formats::NV24), false } },\n+\t\t{ formats::NV42, { JCS_YCbCr, PixelFormatInfo::info(formats::NV42), true } },\n+\t};\n+\n \tconst auto iter = pixelInfo.find(format);\n \tif (iter == pixelInfo.end()) {\n \t\tLOG(JPEG, Error) << \"Unsupported pixel format for JPEG encoder: \"\n","prefixes":["v2"]}