From patchwork Tue Dec 8 03:42:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10606 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 7FAEBBDB20 for ; Tue, 8 Dec 2020 03:43:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A0AC67E6E; Tue, 8 Dec 2020 04:43:16 +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="Fh7yX1cf"; dkim-atps=neutral Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84EC360323 for ; Tue, 8 Dec 2020 04:43:15 +0100 (CET) Received: by mail-pl1-x631.google.com with SMTP id u4so596584plr.12 for ; Mon, 07 Dec 2020 19:43:15 -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=wfuHnw/o1BEKzZB+FNrcaj5EYzRpluI2L6jqwUrfoeU=; b=Fh7yX1cfyZkBmBjFAgeAtsTr9QmP5JQO8wDwBYnqpPalWiuNvgmm5fnk318PkBwgyg Wa8Yinx1TVs0W2nNT19AhN8/S+69+LK6btqtq8EPc+5KUvZnt/5my/VQpd/uX4mmIoaP 9k+/BBgTaAWm0/Q0uoqLeV+BalCfxMNdrsKkg= 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=wfuHnw/o1BEKzZB+FNrcaj5EYzRpluI2L6jqwUrfoeU=; b=QD+J5/GgTjM1it372jaIbE5gZY+3e9NQKt/7pScef4uyELKEVDhvSqAz17MZJ/Fp3n ACRy+ClL0Yj3mKSUz/PNrbn2ZixhVoYBFg5678OU+8NUfp/8PSQUZD8qHmo8YAMtJKVp bDimrghfmx1+Xfs02CqAALXdIdcsnwqep/zmIXmNWFTZHXjGgZWgXzGH/nGgridNDCNW Vk1o8p81l+3pheM3D9ChH7O19uY7jZypxZxEwbbVg/A/r2igmey8Lmgg30gmtl+tJkA+ dcBAMa1CGWnYLk0PphhXTtZyzsaT6oZtKyA+dHYzQTslgRmxcfIUKneq17cXx6i5hhdR 5SmQ== X-Gm-Message-State: AOAM533qMFGzrbWcoN8wTbraKHK5lWacPKlelHdFs6fKtDSfmnX8UXG+ 47Ig2ljSCmJ+nXkbWcu/K/3oUKMyB9f+PDpC X-Google-Smtp-Source: ABdhPJwzF3QI0lpZV2Daha3GIFSq/0WBHhhJT/Y5K1ypJ34IIBr+cKU9pqQTXVpGhBFNBaNajC/UHw== X-Received: by 2002:a17:902:8649:b029:d9:fcd9:522a with SMTP id y9-20020a1709028649b02900d9fcd9522amr19542708plt.83.1607398993898; Mon, 07 Dec 2020 19:43:13 -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 y23sm9028227pfc.178.2020.12.07.19.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 19:43:13 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 03:42:31 +0000 Message-Id: <20201208034234.2501401-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- 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 Tue Dec 8 03:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10607 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 CCBEEBDB20 for ; Tue, 8 Dec 2020 03:43:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9807E67E73; Tue, 8 Dec 2020 04:43: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="fRxEvpEr"; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AD89D60323 for ; Tue, 8 Dec 2020 04:43:17 +0100 (CET) Received: by mail-pg1-x541.google.com with SMTP id q3so10981841pgr.3 for ; Mon, 07 Dec 2020 19:43: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=bn6qloI14/XxoKkaaU/3ozqIDHRP8A2R2v0PN9GFrYs=; b=fRxEvpErRPBqL0KFNv8lDYmisTGRjfpsJpWFN8uYUqKCJ3gzzG3v69E2wl7whTVMhq DS1smu+BEaoaHq2Z9NegOFovQXPeXo1pUJRn7Y1qDXumrDth+rrF6A9KRXNtM4I+FRsC pEYFXKA8PfBRrKQQuWpPlRlKrT07Iuq/1+FVI= 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=bn6qloI14/XxoKkaaU/3ozqIDHRP8A2R2v0PN9GFrYs=; b=mDnDcXpdMzd2WU3pffoDgtQZejMZc1YLXicXK2kUD95YGfwXwoqpPC2ph7UUOSLiw1 0YWn40fdaUlsXV2LanCdhvenHr71LjDBCjAAawaa0Xx6I1PzOr17vxSiJ2pkNsAFQUOu 3j2yVr83Aln3yALSV44gGTap7B9E2HGfRQWI/6BvtOHbZSBozoXAa2Vzx+cJ8lm/oxNF ErV53djQURmPyQpABVO4TVM/f5l3w/w+trMnpzBxasc65vYzwFiz4rLVeD0VICWw2NkU XLN2FldCyP5GTT8Kwby8/6jsDOqdZjDGdfmBj4EOk/cuVSj0BDipzat8r8/a0+UIO0XO ktdA== X-Gm-Message-State: AOAM532UGWWM+3acG3Tr1QxQnBA/o6fOs9Jxh5TBdye9AUyM8Eyejz1H eO1Pua828JxZpVQKz6VWG1FxLIxz9kO5Wd9N X-Google-Smtp-Source: ABdhPJyxJHPHa0R1XX2IUs+raay1Z6oxMyO0QVLRi3vM8ts1FF5cqwgRdZt5iRWqnZApGa+4DlbTNQ== X-Received: by 2002:a63:a902:: with SMTP id u2mr21368281pge.263.1607398995499; Mon, 07 Dec 2020 19:43: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 y23sm9028227pfc.178.2020.12.07.19.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 19:43:14 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 03:42:32 +0000 Message-Id: <20201208034234.2501401-2-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201208034234.2501401-1-hiroh@chromium.org> References: <20201208034234.2501401-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- 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 Tue Dec 8 03:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10608 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 56FF1BDB20 for ; Tue, 8 Dec 2020 03:43:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 22E7D67E6F; Tue, 8 Dec 2020 04:43:20 +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="ll7ii2tL"; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B044D67E74 for ; Tue, 8 Dec 2020 04:43:18 +0100 (CET) Received: by mail-pg1-x543.google.com with SMTP id o4so10973113pgj.0 for ; Mon, 07 Dec 2020 19:43: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=t05elDKU5gwArfQXcC3tSZPtb0HxD6iK81Yc5ozHsC4=; b=ll7ii2tL3dsOcI8B/DmLvcaHccNaLLLOeSErg+Zyt4rMnPzTuFzeOXSnrIeysNHodq YvXAqmEruvZcMkDuv6szHVuUiGbnS4bzr+EOXBr3jcNyUr9PFl2piUhfnI7y1xicyyEg yRAhLivokgJnHOx+28QDzWDIdjDXI/rwCcBdE= 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=t05elDKU5gwArfQXcC3tSZPtb0HxD6iK81Yc5ozHsC4=; b=aOrT5ks0K+gfvdVS28+K6o4cwlHpC8JxL8q9A8+DT8Dj1xX+/RthT8tTvRQKBMr/7V xsaAgKbySHjcoUeRXd6DtqjQfei44oiane5Q8K7kIlsf+LuXiiDkgPxIv0tcD+w1EuXD mHu90RoIOQCOh/CY5dTV+cGoUZa6+r4Uid5xcpC5HVG6crFjbgsN9p9vd4w2efgy31XS aEBG339P4SAnor+Rxsx6iIrPD71sUOY21EkBGW6UaENQMC7ejoJ9UQfNgj9+qZ/QzXZm 3w2t3K3RiiAhlbWP1gvpgGU8RY219V0i/UhxOZRKvwoQ6WlL+c/dxuTTjE/3fl53NaVj hczA== X-Gm-Message-State: AOAM531LLtPRdngwa1ZZZrbjygP+PmGmHxrrxAS3arzO9dyZ6LPv06kb xsKsWILAclXcghHIlwTCDUgHiF6ADxNqKp2E X-Google-Smtp-Source: ABdhPJw8paD00u3X+x79zpiUjS+dHLS8NpJylLGxnzmpO708QPc1DcBI/Y/iB/okK6iK9PjDo4oHIg== X-Received: by 2002:a17:90a:e604:: with SMTP id j4mr2154110pjy.19.1607398997069; Mon, 07 Dec 2020 19:43: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 y23sm9028227pfc.178.2020.12.07.19.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 19:43:16 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Dec 2020 03:42:33 +0000 Message-Id: <20201208034234.2501401-3-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201208034234.2501401-1-hiroh@chromium.org> References: <20201208034234.2501401-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- src/android/camera_device.cpp | 108 +++++++++++++++++++++++++++++++++- 1 file changed, 106 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..36d0b343 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,108 @@ 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 +1435,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) {