From patchwork Thu Jun 19 08:20:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 23599 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 D7B82BDE6B for ; Thu, 19 Jun 2025 08:20:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2D9E668DCD; Thu, 19 Jun 2025 10:20:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QQpoBtDB"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0379761538 for ; Thu, 19 Jun 2025 10:20:33 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-311a6236effso301126a91.2 for ; Thu, 19 Jun 2025 01:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1750321232; x=1750926032; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fUCzg5s08phrQ6T9dtFo1JDLc8L13lmp2iapjNFek6Q=; b=QQpoBtDBswbfUnKjp/9SmHWjXVrb2G9fWglfjfOZ9me53ZsKeFoXvb5XJb9oBH0lU4 OW2ajJivZU1O26ZRr+vURjUAHDepiOgOEKaup5wkRx01eUo06iNktyV0+uZeh8SqDCcJ pkCnPn5/h320zeDoFQHxsVGwwKt7ZXyGEmttM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750321232; x=1750926032; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fUCzg5s08phrQ6T9dtFo1JDLc8L13lmp2iapjNFek6Q=; b=V5xa+7Hrube6wgOr1oPddXPhNLMjZb+wZBdHQdCnrAzHlcmInK6KRSV7EEnr5aswhW MuXqXTOwPBDQsuK7zIQ6562h2ZG/BFoIuRN2BeOpesSsbDVEJ7iDhUy0NYZkJ72doInF yQ9eRgznt9m/NcxHmZZJWoK+67AUKYiNO++9hArZ7+TC8TlOR+QspHvz3b6momNPQ9ma +gKLAKVU6vqeOq/PCAmXRS/hNFLUyxkLMGMRvwMMgNBSoDoGtz86fjawk+qeA4MrHEl+ 3/X6lceqRXgtrAIgmItFk4sLwv1wdS1o31/Gws7WCTPLQsSW5xCjQ9qqSN4DHDZc+fk4 ELmQ== X-Gm-Message-State: AOJu0YxzVlS6ntQ4tz4wBhAmpA5ORzI3WWQU21v83P/nMZf87XVtqXKx zVvefNeX40jO3gZBU4XRSoX/ePtkcbhn1X9FAcMmPc9eU+AqdxusAu4xfUj8iCn3xsi8MW52OqW 8i3s= X-Gm-Gg: ASbGncsdekg7jJyoyMLQ2bIUsnUDDEQ1SFkfUXypWpERd1yBSt5RgDx2hdPM486l22l FjMHBPS4AmeopSt/ORZM4prcwEYE2rS9aTQe+dRArasRkQ/13vsr3LxqQOUQyjIvdGKXdT70nsA LNfvy0kvkx0uZrSE+CYVWXOQdzCHUskKHElpziR49WOKxlShN55aehdnFb8PAOKGFe1dhJfEQtF RrVusDb+nnmv0+XNXZwBV8kFF5NLltTqbYxzsFQ2clQrvrxR0y2Iq+I2P82YNwTC/HALWVkPzyg Q5CVoyfTpc0KkMbrCaro1L+dlzZf+1Le++YxOA5HYIyrhyrnxmbtmlPfIgdUdfGNEpZLvnTlIZI qbYAKxUxzsjztsDnyqm3Hj8vMMOc29W9QEPVGxMBF5v6SS/DrJDuPzrFe8OjzLaleeA== X-Google-Smtp-Source: AGHT+IEWKLPH2EAwBIDZZEaUO9VGLQ0DuBH3r4UwODMa0BPTxgX1C1ssri/uNcaCFwNefqrVAE7MaQ== X-Received: by 2002:a17:90b:1c04:b0:312:f2ee:a895 with SMTP id 98e67ed59e1d1-313f1e1a908mr26451646a91.31.1750321232143; Thu, 19 Jun 2025 01:20:32 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (208.158.221.35.bc.googleusercontent.com. [35.221.158.208]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3158a24bc2fsm1526588a91.22.2025.06.19.01.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 01:20:31 -0700 (PDT) From: Harvey Yang X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang 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 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang Previously, const global `pixelInfo` in `encoder_libjpeg.cpp` is initialized before const global `pixelFormatInfo` in `formats.cpp`, even if `formats.cpp` is wrapped in the base libcamera shared library, and the android adapter (which contains `encoder_libjpeg.cpp`) depends on the base libcamera shared library. The reason should be that C++ initialization order doesn't follow the linking process. This patch migrates const global pixelInfo to static to avoid the race condition. Signed-off-by: Harvey Yang --- src/android/jpeg/encoder_libjpeg.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index cb242b5ec6a8..3ba5103d5ad5 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -38,26 +38,26 @@ struct JPEGPixelFormatInfo { bool nvSwap; }; -const std::map pixelInfo{ - { formats::R8, { JCS_GRAYSCALE, PixelFormatInfo::info(formats::R8), false } }, - - { formats::RGB888, { JCS_EXT_BGR, PixelFormatInfo::info(formats::RGB888), false } }, - { formats::BGR888, { JCS_EXT_RGB, PixelFormatInfo::info(formats::BGR888), false } }, - - { formats::NV12, { JCS_YCbCr, PixelFormatInfo::info(formats::NV12), false } }, - { formats::NV21, { JCS_YCbCr, PixelFormatInfo::info(formats::NV21), true } }, - { formats::NV16, { JCS_YCbCr, PixelFormatInfo::info(formats::NV16), false } }, - { formats::NV61, { JCS_YCbCr, PixelFormatInfo::info(formats::NV61), true } }, - { formats::NV24, { JCS_YCbCr, PixelFormatInfo::info(formats::NV24), false } }, - { formats::NV42, { JCS_YCbCr, PixelFormatInfo::info(formats::NV42), true } }, -}; - const struct JPEGPixelFormatInfo &findPixelInfo(const PixelFormat &format) { static const struct JPEGPixelFormatInfo invalidPixelFormat { JCS_UNKNOWN, PixelFormatInfo(), false }; + static const std::map pixelInfo{ + { formats::R8, { JCS_GRAYSCALE, PixelFormatInfo::info(formats::R8), false } }, + + { formats::RGB888, { JCS_EXT_BGR, PixelFormatInfo::info(formats::RGB888), false } }, + { formats::BGR888, { JCS_EXT_RGB, PixelFormatInfo::info(formats::BGR888), false } }, + + { formats::NV12, { JCS_YCbCr, PixelFormatInfo::info(formats::NV12), false } }, + { formats::NV21, { JCS_YCbCr, PixelFormatInfo::info(formats::NV21), true } }, + { formats::NV16, { JCS_YCbCr, PixelFormatInfo::info(formats::NV16), false } }, + { formats::NV61, { JCS_YCbCr, PixelFormatInfo::info(formats::NV61), true } }, + { formats::NV24, { JCS_YCbCr, PixelFormatInfo::info(formats::NV24), false } }, + { formats::NV42, { JCS_YCbCr, PixelFormatInfo::info(formats::NV42), true } }, + }; + const auto iter = pixelInfo.find(format); if (iter == pixelInfo.end()) { LOG(JPEG, Error) << "Unsupported pixel format for JPEG encoder: "