From patchwork Wed Dec 9 05:54:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10620 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 55F35BDE19 for ; Wed, 9 Dec 2020 05:54:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9B0B67F31; Wed, 9 Dec 2020 06:54:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dv2dV+XR"; dkim-atps=neutral Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 907CD67F0B for ; Wed, 9 Dec 2020 06:54:17 +0100 (CET) Received: by mail-pj1-x1042.google.com with SMTP id m5so303391pjv.5 for ; Tue, 08 Dec 2020 21:54:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ha1qEOXC4zJGgg3PbuEXW93Vpopx9aFVJPSPCxvQKSU=; b=dv2dV+XRT/8jw01GHWUIWVppI9QuAs3Jd6MQVJKikBVyqaXqBarLvCmsrvouInzOnX 4Kn28vVlp2k/uwvb2+IuX6KN1pDFzHQGhLs5UCOxrJ/fdsOFkZ9agqlZJ44MOOBPimdY a5jnZYwGrLbdxbt47q0nxhYHKowDM6Ngs1P/s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ha1qEOXC4zJGgg3PbuEXW93Vpopx9aFVJPSPCxvQKSU=; b=a13bhRM6hoXB+ysLvdmSGkb4ab8Yc1AFcmp51MreR5/hO6EQGS8gmH0vowls4m6MrQ llfS471m2YbsZ6sX5/vHWujtZLmRvWpQdofCUjzAC2MEX2CYcGwAil9TOj7iXSlbjFns 24Kkv2/f3hQheglnuzz2N8HrkYxOSr6+NERXDmq5B74Pa182jdfmdFsMshvIpHeT9ukB H5HWFUsTk4F6l8BUaUTpK1B2LvAMSCFDWWwfOjxOkdh1caisHiiuPjHe23pZzUKuydVB fESLj0jjJMkgnBq2lad2sCwuhokrIIyYCX54QVq0ANektHHxe63ZVA1Cb7FgAmNAe+xE x5qw== X-Gm-Message-State: AOAM533VqXOlAPjlc4VrQJ3BTNhc87NAbgGeUct2hfMcKIEAY7iLuBcs vtxsreldpWBNMdfh6DNVpEdp+37MFqnZCg== X-Google-Smtp-Source: ABdhPJz2s3TpTvIqOwVWNc5Ownb/HPrY1g2LlQBbZIx9E0BTnKFjwmVl6jQeFJkBWxMGvvq/1786Gg== X-Received: by 2002:a17:902:bf44:b029:da:d0ee:cef with SMTP id u4-20020a170902bf44b02900dad0ee0cefmr914026pls.12.1607493255573; Tue, 08 Dec 2020 21:54:15 -0800 (PST) Received: from hiroh.c.googlers.com.com (128.141.236.35.bc.googleusercontent.com. [35.236.141.128]) by smtp.gmail.com with ESMTPSA id oc13sm641275pjb.5.2020.12.08.21.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 21:54:14 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 9 Dec 2020 05:54:08 +0000 Message-Id: <20201209055410.3232987-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/3] android: camera_device: Introduce Camera3StreamConfig 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" Camera3StreamConfig is a new class to store camera3_stream and types with associated StreamConfiguration. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 675af570..09269d95 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -128,6 +128,18 @@ const std::map camera3FormatsMap = { }, }; +/* + * \struct Camera3StreamConfig + * \brief Data to store StreamConfiguration associated with camera3_stream(s). + * \var streams List of streams requested by Android HAL client. + * \var types List of CameraStream::Type associated with streams. + * \var config StreamConfiguration for streams. + */ +struct Camera3StreamConfig { + std::vector streams; + std::vector types; + StreamConfiguration config; +}; } /* namespace */ LOG_DECLARE_CATEGORY(HAL) From patchwork Wed Dec 9 05:54:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10621 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 82C70BDE19 for ; Wed, 9 Dec 2020 05:54:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 561BF67F35; Wed, 9 Dec 2020 06:54:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MKNylucY"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C114967F30 for ; Wed, 9 Dec 2020 06:54:18 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id t18so380252plo.0 for ; Tue, 08 Dec 2020 21:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6VIwJqNsRrz20X5OvIZRqQ98fMAo2kwuGK5JAcIcoNI=; b=MKNylucY2CpiAPRwVSt0DfY9Gik7LE8t5kNPmw6UZoGvmQRhVnwsMAVXMBYNWhMbG/ MYHFIrMouGLjZxGK8j2ZK86Gg/Df6k8Ve6pb/e5GSVFYITTm7+ZKT9n3kXNGbmhvG4Zs OSVJ8x2ojm/yUzGyftclF5RS9Mn4zMuJei0n8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6VIwJqNsRrz20X5OvIZRqQ98fMAo2kwuGK5JAcIcoNI=; b=Fh6p1wv+q+yAEUIU8Go9JCkIXSoXib/d9RgtUiuGOMw+LQ7h2+gh7SarjCSAcmF4Mp VKhSy5OUeONXNtm3fznMC4zt0IaVkp9dLvEPTWeLX0lEyHocdX/q59Ux3DfysNqcK2AU hLvF9XAZ3vmMqJ9RXuYq4ArdxLEoj2AXp90BxkZMPMTVWNKcM2GVI+TDMTmy1MbvAjq/ GDRxY0PmuuEXnC2Mts8baH+zJuVYRRPlBWPYCt+lgRvgDqixl1r5pckO8a1xqjhI88nb X1lXBPhjNxYBZvikpmSRusjb0bMbuLpJRiI7M48W3X1yvkMGlO+qaz077850NzMG28un sC9w== X-Gm-Message-State: AOAM532lp90D9ZEh/VfXZHiKgIu+rpXQHoSd3n2Mu8Gk1hNFE3dLHWwI khst4//OD1GyxDRMbUq6xJTrwUvSge4L9A== X-Google-Smtp-Source: ABdhPJy6jfdWH08ZYDiJ11GEcw5qWR3Iazcn0mBLEfKtnXnxIHv5wPfpnb51sLdpApY1hrM1lYWYtA== X-Received: by 2002:a17:90a:6842:: with SMTP id e2mr773777pjm.190.1607493257156; Tue, 08 Dec 2020 21:54:17 -0800 (PST) Received: from hiroh.c.googlers.com.com (128.141.236.35.bc.googleusercontent.com. [35.236.141.128]) by smtp.gmail.com with ESMTPSA id oc13sm641275pjb.5.2020.12.08.21.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 21:54:16 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 9 Dec 2020 05:54:09 +0000 Message-Id: <20201209055410.3232987-2-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201209055410.3232987-1-hiroh@chromium.org> References: <20201209055410.3232987-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/3] android: camera_device: Use Camera3StreamConfig in configureStreams() 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" Use the newly introduced Camera3StreamConfig to associate the Android requested streams with the associated StreamConfiguration in a vector of configurations. This change prepares to sort the vector of configuration before using it to configure the Camera and populate the streams_ vector. No functional changes intended. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 52 +++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 21 deletions(-) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 09269d95..b7bf3d88 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1240,6 +1240,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streams_.clear(); streams_.reserve(stream_list->num_streams); + std::vector streamConfigs; + streamConfigs.reserve(stream_list->num_streams); + /* First handle all non-MJPEG streams. */ camera3_stream_t *jpegStream = nullptr; for (unsigned int i = 0; i < stream_list->num_streams; ++i) { @@ -1270,14 +1273,12 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) continue; } - StreamConfiguration streamConfiguration; - streamConfiguration.size = size; - streamConfiguration.pixelFormat = format; - - config_->addConfiguration(streamConfiguration); - streams_.emplace_back(this, CameraStream::Type::Direct, - stream, config_->size() - 1); - stream->priv = static_cast(&streams_.back()); + Camera3StreamConfig streamConfig; + streamConfig.streams = { stream }; + streamConfig.types = { CameraStream::Type::Direct }; + streamConfig.config.size = size; + streamConfig.config.pixelFormat = format; + streamConfigs.push_back(std::move(streamConfig)); } /* Now handle the MJPEG streams, adding a new stream if required. */ @@ -1286,9 +1287,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) int index = -1; /* Search for a compatible stream in the non-JPEG ones. */ - for (unsigned int i = 0; i < config_->size(); i++) { - StreamConfiguration &cfg = config_->at(i); - + for (size_t i = 0; i < streamConfigs.size(); ++i) { + const auto &cfg = streamConfigs[i].config; /* * \todo The PixelFormat must also be compatible with * the encoder. @@ -1310,28 +1310,38 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) * introduce a new stream to satisfy the request requirements. */ if (index < 0) { - StreamConfiguration streamConfiguration; - /* * \todo The pixelFormat should be a 'best-fit' choice * and may require a validation cycle. This is not yet * handled, and should be considered as part of any * stream configuration reworks. */ - streamConfiguration.size.width = jpegStream->width; - streamConfiguration.size.height = jpegStream->height; - streamConfiguration.pixelFormat = formats::NV12; + Camera3StreamConfig streamConfig; + streamConfig.config.size.width = jpegStream->width; + streamConfig.config.size.height = jpegStream->height; + streamConfig.config.pixelFormat = formats::NV12; + streamConfigs.push_back(std::move(streamConfig)); - LOG(HAL, Info) << "Adding " << streamConfiguration.toString() + LOG(HAL, Info) << "Adding " << streamConfig.config.toString() << " for MJPEG support"; type = CameraStream::Type::Internal; - config_->addConfiguration(streamConfiguration); - index = config_->size() - 1; + index = streamConfigs.size() - 1; } - streams_.emplace_back(this, type, jpegStream, index); - jpegStream->priv = static_cast(&streams_.back()); + streamConfigs[index].streams.push_back(jpegStream); + streamConfigs[index].types.push_back(type); + } + + for (const auto &streamConfig : streamConfigs) { + config_->addConfiguration(streamConfig.config); + for (size_t i = 0; i < streamConfig.streams.size(); ++i) { + camera3_stream_t *stream = streamConfig.streams[i]; + const CameraStream::Type type = streamConfig.types[i]; + streams_.emplace_back(this, type, + stream, config_->size() - 1); + stream->priv = static_cast(&streams_.back()); + } } switch (config_->validate()) { From patchwork Wed Dec 9 05:54:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10622 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 2AC47BDE19 for ; Wed, 9 Dec 2020 05:54:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A2EE767F33; Wed, 9 Dec 2020 06:54:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Xwq/SwKx"; dkim-atps=neutral Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6906367F2F for ; Wed, 9 Dec 2020 06:54:20 +0100 (CET) Received: by mail-pj1-x1043.google.com with SMTP id z12so291579pjn.1 for ; Tue, 08 Dec 2020 21:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ou0CpixUBht67VFwIfiQUkkAuYyABRXfhf8Z18Fbfr8=; b=Xwq/SwKxclPijT+ujet7KF5nKl5lMp3CMJ4oE9ZOg2IHc5PZWsZ4XhTIbUZRfWnqwO CDXUcCrDjpTj454EPBW7OAl3gF8mB7QzTClxAnrNkN+HVTo8ys5qmgbH+VICygwYSTjI Sp16Zt71m1DeQJRJnlmTylp7POQnzoQq9xXGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ou0CpixUBht67VFwIfiQUkkAuYyABRXfhf8Z18Fbfr8=; b=X95FgUeQlNaN9cGqt8plrOtT8x4rqeU00BgA0pLetOZEyvP+XfiJcg6VRU5iN2rbDO XUIlr/rEtl+J4mO/99gPfedp4EGCOliXjDKx4o7K9NPYp6JRnpbfIGNgglpA7F9uEhoQ ENPD3f+GTFgZvrifML8J97qgNASQNcXQthDjahJHuQxrE8qHB7UjIQbT8vCn/4i+WQs2 ZaBxnZRbAqKFGz9KZjLpVeHKOyG+8YQdIJsbbJ/oI0OD7GDNh9V24tNQa6QiE+7kkziq eDHyilbobTJtVwqxJX/Ng0o7nblb+1zuG4mW+m3+OLdLI1anFoGI3+YNlv/cMmW3KMi7 yewg== X-Gm-Message-State: AOAM533Z3u/Oxx3jLz5+rqLdyYODHS0cUmguqrKPNHgf5OGlBv04MW4H kmmkiFAURsfPz6/DAgInBgBEeCYeRoS1Vw== X-Google-Smtp-Source: ABdhPJwghbeX0Le7A+LgGHxp1m5SlC9JPSo83DKfgOA9q3tjyI7x/vNeADNmwQbFtTAb/liJhHQjHw== X-Received: by 2002:a17:902:c3d2:b029:da:73c5:c589 with SMTP id j18-20020a170902c3d2b02900da73c5c589mr890098plj.71.1607493258789; Tue, 08 Dec 2020 21:54:18 -0800 (PST) Received: from hiroh.c.googlers.com.com (128.141.236.35.bc.googleusercontent.com. [35.236.141.128]) by smtp.gmail.com with ESMTPSA id oc13sm641275pjb.5.2020.12.08.21.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 21:54:18 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 9 Dec 2020 05:54:10 +0000 Message-Id: <20201209055410.3232987-3-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201209055410.3232987-1-hiroh@chromium.org> References: <20201209055410.3232987-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 3/3] android: camera_device: Reorder configurations before requesting 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" This reorders Camera3Configs before executing CameraConfiguration::validate() to make it easier for the Camera to satisfy the Android framework request. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- src/android/camera_device.cpp | 109 +++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index b7bf3d88..c9e0ec98 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -9,6 +9,7 @@ #include "camera_ops.h" #include "post_processor.h" +#include #include #include #include @@ -27,6 +28,8 @@ using namespace libcamera; +LOG_DECLARE_CATEGORY(HAL) + namespace { /* @@ -140,9 +143,109 @@ struct Camera3StreamConfig { std::vector types; StreamConfiguration config; }; -} /* namespace */ -LOG_DECLARE_CATEGORY(HAL) +/* + * Reorder the configurations so that libcamera::Camera can accept them as much + * as possible. The sort rule is as follows. + * 1.) The configuration for NV12 request whose resolution is the largest. + * 2.) The configuration for JPEG request. + * 3.) Others. Larger resolutions and different formats are put earlier. + */ +std::vector sortCamera3StreamConfigs( + std::vector unsortedConfigs, + const camera3_stream_t *jpegStream) +{ + const size_t unsortedSize = unsortedConfigs.size(); + std::optional jpegConfig = std::nullopt; + + if (jpegStream) { + for (size_t i = 0; i < unsortedSize; ++i) { + const auto &streams = unsortedConfigs[i].streams; + if (std::find(streams.begin(), streams.end(), + jpegStream) != streams.end()) { + jpegConfig = std::move(unsortedConfigs[i]); + unsortedConfigs.erase(unsortedConfigs.begin() + i); + break; + } + } + if (!jpegConfig) + LOG(HAL, Fatal) << "No Camera3StreamConfig is found for Jpeg"; + } + + std::map> formatToConfigs; + for (const auto &streamConfig : unsortedConfigs) { + const StreamConfiguration &config = streamConfig.config; + formatToConfigs[config.pixelFormat].push_back(streamConfig); + + } + for (auto &[format, streamConfigs] : formatToConfigs) { + /* Sorted by resolution. Smaller is put first. */ + std::sort(streamConfigs.begin(), streamConfigs.end(), + [](const auto &streamConfigA, const auto &streamConfigB) { + const Size &sizeA = streamConfigA.config.size; + const Size &sizeB = streamConfigB.config.size; + return sizeA < sizeB; + }); + } + + std::vector sortedConfigs; + sortedConfigs.reserve(unsortedSize); + /* + * NV12 is the most prioritized format. Put the configuration with NV12 + * and the largest resolution first. + */ + const auto nv12It = formatToConfigs.find(formats::NV12); + if (nv12It != formatToConfigs.end()) { + auto &nv12Configs = nv12It->second; + const Size &nv12LargestSize = nv12Configs.back().config.size; + /* + * If JPEG will be created from NV12 and the size is larger than + * the largest NV12 configurations, then put the NV12 + * configuration for JPEG first. + */ + if (jpegConfig && jpegConfig->config.pixelFormat == formats::NV12) { + const Size &nv12SizeForJpeg = jpegConfig->config.size; + + if (nv12LargestSize < nv12SizeForJpeg) { + LOG(HAL, Debug) << "Insert " << jpegConfig->config.toString(); + sortedConfigs.push_back(std::move(*jpegConfig)); + jpegConfig = std::nullopt; + } + } + LOG(HAL, Debug) << "Insert " << nv12Configs.back().config.toString(); + sortedConfigs.push_back(std::move(nv12Configs.back())); + nv12Configs.pop_back(); + } + + /* If the configuration for JPEG is there, then put it. */ + if (jpegConfig) { + LOG(HAL, Debug) << "Insert " << jpegConfig->config.toString(); + sortedConfigs.push_back(std::move(*jpegConfig)); + jpegConfig = std::nullopt; + } + + /* + * Put configurations with different formats and larger resolutions + * earlier. + */ + while (!formatToConfigs.empty()) { + for (auto it = formatToConfigs.begin(); it != formatToConfigs.end();) { + auto& configs = it->second; + if (configs.empty()) { + it = formatToConfigs.erase(it); + continue; + } + LOG(HAL, Debug) << "Insert " << configs.back().config.toString(); + sortedConfigs.push_back(std::move(configs.back())); + configs.pop_back(); + it++; + } + } + assert(sortedConfigs.size() == unsortedSize); + + return sortedConfigs; +} +} /* namespace */ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags) @@ -1333,6 +1436,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfigs[index].types.push_back(type); } + streamConfigs = sortCamera3StreamConfigs(std::move(streamConfigs), + jpegStream); for (const auto &streamConfig : streamConfigs) { config_->addConfiguration(streamConfig.config); for (size_t i = 0; i < streamConfig.streams.size(); ++i) {