From patchwork Fri Dec 11 09:53:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10642 X-Patchwork-Delegate: jacopo@jmondi.org 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 11A6CBD80A for ; Fri, 11 Dec 2020 09:53:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8325363500; Fri, 11 Dec 2020 10:53:47 +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="JZVHIClT"; 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 D497A600FF for ; Fri, 11 Dec 2020 10:53:45 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id p6so4328274plr.7 for ; Fri, 11 Dec 2020 01:53:45 -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=IyosWRtwBOSokEIMBoa511MH2JrPPvE2nFDDSk4QwmU=; b=JZVHIClT7nfpNFz0lbPTHX3uEeyN4DQ0YIkIoJ1lqiEV4L/hvxC9mfTq8mUFojVIxr JvbZa/qGeaNYBqKBPrTwFNZ3sQQQZQ2IowK7R6/2C1zQUvivF9FxzSYJO4SHjYqbBv1u fcQxpt7e/hLcKpwH5C7aaY1e6xBK0j67kesMU= 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=IyosWRtwBOSokEIMBoa511MH2JrPPvE2nFDDSk4QwmU=; b=TPparQ1Dlg+AfrxlIpvy+6aNkXjTdbQBCpy7xPO8jBVstTn5Ah3VIuMHFNOrD0K1Ry GVQUiS4Lhxuvmlgc4irKj7Tt297Cvkhp6bHxghAsWtP8wb2/Kqhb0/E3FIinOqG/jQ2y 8ngDKHtNfeGxDtJsBRDQBf7afKNd1JK/DsCjlL4fStSVB1iiYNsju4z5reEO3gwqfjOc RxLwxKJpmAC/VRqnOni9ZtQzj5xtIzlG7KSvXGcZJW1Ox0OvXGXl0ti3BW1Vy1scmG9w 8kK4pj3adnYvkGP+IP9312mqvRmDMyrZu2oN/cFicRcfmj8ED9+9o1qRFEmg0HJjOkUx taVA== X-Gm-Message-State: AOAM530G8CYR9h/cuuPzE+vzuf3q6352qoU7BL6y1cO9akjQO1O36d1r fb4t2gc/o61gVdtX87C4cMIbvxGK6XFF0gjx X-Google-Smtp-Source: ABdhPJz9tzXsGGkJRpdQM8Fn5XIqhijrdVwu7szQEglz+KyQO30F6zePtTvsdSfGxtFZut8o30TxYA== X-Received: by 2002:a17:90b:1294:: with SMTP id fw20mr12206107pjb.187.1607680423088; Fri, 11 Dec 2020 01:53:43 -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 a17sm8363364pgw.80.2020.12.11.01.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 01:53:42 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 09:53:34 +0000 Message-Id: <20201211095336.40500-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 872c7b18..f4a6fb6b 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -128,6 +128,22 @@ const std::map camera3FormatsMap = { }, }; +/* + * \struct Camera3StreamConfig + * \brief Data to store StreamConfiguration associated with camera3_stream(s). + * \var streams List of the pairs of a stream requested by Android HAL client + * and CameraStream::Type associated with the stream. + * \var config StreamConfiguration for streams. + */ +struct Camera3StreamConfig { + struct Camera3Stream { + camera3_stream_t *stream; + CameraStream::Type type; + }; + + std::vector streams; + StreamConfiguration config; +}; } /* namespace */ LOG_DECLARE_CATEGORY(HAL) From patchwork Fri Dec 11 09:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10643 X-Patchwork-Delegate: jacopo@jmondi.org 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 2FB0DBD80A for ; Fri, 11 Dec 2020 09:53:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED4446346D; Fri, 11 Dec 2020 10:53:49 +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="hkvj0clT"; dkim-atps=neutral Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E0CB86346D for ; Fri, 11 Dec 2020 10:53:46 +0100 (CET) Received: by mail-pl1-x643.google.com with SMTP id bj5so4336019plb.4 for ; Fri, 11 Dec 2020 01:53:46 -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=yoK5XFHb4HhZWfB4dpOlsDWxHSKmTJdiIr+Nywe5htw=; b=hkvj0clTbHToFNIvlV2FkKDsw98qFt8AF5iJ/B7Eqdw4wnkkfzoL62GNktSj93YVtj ett/DSHE5mbV8+uqi9+7u87xOE/+CZXi1v/qbqEpuJNA5ZFaY6QQZugHvKTwkwU4GQ5p RzOZ9ng+h87Y4Wpe+284DcRqXpjvJe9yi5Nh4= 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=yoK5XFHb4HhZWfB4dpOlsDWxHSKmTJdiIr+Nywe5htw=; b=fxYva9ab/VjxQI7wDB1zI4Mr6s+bZwH82yOThnXcO/aoW2f8Q9OzSSUWxbsWi2tZbh VuwtTHVM4vWVNvfTsX7/rHb0dWp10ZQFVA7YteGjwCDIj9a7D3kY1ScTdUnqDPXTDHV6 4/HKnuINbOECYr05ICzAPe0wFN5cVB8er7KmbYxC1DIXG+3iDGKfTU8F+xGOjm3fFaGP Mk6jipMPkR6qv3BND22s9rLMpgXzfMS7Ha0ylmvQXqfXknarSaxtnUfAGwdCSiJ6aI/Z 3rx0kJZw41bZhwTHEYKHLsSneyvrZnhZgfpog+S8iaC3EGmpXN3tXLB1RchzaP9Uukbw 0vvg== X-Gm-Message-State: AOAM530a2nAHGwS47kwDu5yIYInhGNGZXmrEtKdHjHAAxPTekwQJ6Tlz hfLWoEMRI8Bfw3gxcETddVxrRHQKcLhFTtcN X-Google-Smtp-Source: ABdhPJx6UfOTyL07m2KOI3kXBWF4V33TkiSlzkDi0zOWMIZgNCCfOkmEZAx5iDK+kYCZuqihWsBM9w== X-Received: by 2002:a17:90a:970b:: with SMTP id x11mr12334836pjo.16.1607680425310; Fri, 11 Dec 2020 01:53:45 -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 a17sm8363364pgw.80.2020.12.11.01.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 01:53:44 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 09:53:35 +0000 Message-Id: <20201211095336.40500-2-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201211095336.40500-1-hiroh@chromium.org> References: <20201211095336.40500-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 | 48 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f4a6fb6b..7e8b2818 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1264,6 +1264,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) { @@ -1294,14 +1297,11 @@ 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, 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. */ @@ -1310,8 +1310,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 @@ -1334,28 +1334,36 @@ 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, type }); + } + + for (const auto &streamConfig : streamConfigs) { + config_->addConfiguration(streamConfig.config); + + for (auto &stream : streamConfig.streams) { + streams_.emplace_back(this, stream.type, stream.stream, + config_->size() - 1); + stream.stream->priv = static_cast(&streams_.back()); + } } switch (config_->validate()) { From patchwork Fri Dec 11 09:53:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10644 X-Patchwork-Delegate: jacopo@jmondi.org 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 DFE54BD80A for ; Fri, 11 Dec 2020 09:53:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F8E267E6B; Fri, 11 Dec 2020 10:53:50 +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="NoiyeHtS"; dkim-atps=neutral Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED4B3600FF for ; Fri, 11 Dec 2020 10:53:48 +0100 (CET) Received: by mail-pl1-x641.google.com with SMTP id t18so4350218plo.0 for ; Fri, 11 Dec 2020 01:53:48 -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=PshUzRB1+t2w08FIhupSaj8N5u9sFU7dZzaCHxWt0YA=; b=NoiyeHtSR9SWjVob2SxDJGrYB51VRLJdCAGkPKevXLDPP4T0BWwTpq2qWc/1GKl0JU mzdHrqsUzOsy6NdT/6Og83JNme/VryaGgQvfOF6drCkNzcDl8gwC9AZq8sdII/RFInRO sUuoRCQmc71oGLlJqY4Pcd6rzhRe51GKKTDkE= 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=PshUzRB1+t2w08FIhupSaj8N5u9sFU7dZzaCHxWt0YA=; b=Km0Vc1043oeL8qj4iCco+tz5CzaATwSRV8b9GNno+RmPa2uc4iosCsekOWg2nN2nUA bcAPUvanV5UKIALiBDHabIr/KU6r+LV7BEKHMS+2acXRZbZT0fApUnXOehw4sLEzG50A yP5YuRE9rBTj+a7SjEwBEgjnnjaw0QUQArLDvFHWEadkr1jo9Ro931IUyGN7WpLrC/xL gPEmgJHDe+9GiPQ9SkyyKy08ugzbqfRUwhAw938YsiJhu948Fj30NkPz+yWaJmjvxotD a/78Dz+NKb5LA2cy56RgyVf3xFQLEN/z7G+O5/b0FNJMotap9+rfDcNR5vbFWdBNklDz sMoQ== X-Gm-Message-State: AOAM53073oISpYIm8O8SH4ha5A+rN7jMb7yfPlKYNqE20Fp6qqWUGQ8G MBEvK4ASEmzhnktHwUZg6PSwVqRU+a3nDLiw X-Google-Smtp-Source: ABdhPJy0/j46dwUE4oEUPn6cW2ldQu4h5wYbIZKJMYTIayOy3i36dIb6kOh++UPnWixCYHEBYJRBgg== X-Received: by 2002:a17:90a:bb83:: with SMTP id v3mr12302242pjr.28.1607680427345; Fri, 11 Dec 2020 01:53:47 -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 a17sm8363364pgw.80.2020.12.11.01.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 01:53:46 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 09:53:36 +0000 Message-Id: <20201211095336.40500-3-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201211095336.40500-1-hiroh@chromium.org> References: <20201211095336.40500-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 110 +++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) -- 2.29.2.576.ga3fc446d84-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 7e8b2818..0c58c1c5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -27,6 +27,8 @@ using namespace libcamera; +LOG_DECLARE_CATEGORY(HAL) + namespace { /* @@ -144,9 +146,112 @@ struct Camera3StreamConfig { std::vector streams; 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. + */ +void sortCamera3StreamConfigs(std::vector &unsortedConfigs, + const camera3_stream_t *jpegStream) +{ + const Camera3StreamConfig *jpegConfig = nullptr; + + std::map> formatToConfigs; + for (const auto &streamConfig : unsortedConfigs) { + if (jpegStream && !jpegConfig) { + const auto &streams = streamConfig.streams; + if (std::find_if(streams.begin(), streams.end(), + [jpegStream](const auto &stream) { + return stream.stream == jpegStream; + }) != streams.end()) { + jpegConfig = &streamConfig; + continue; + } + } + formatToConfigs[streamConfig.config.pixelFormat].push_back(&streamConfig); + } + if (jpegStream && !jpegConfig) + LOG(HAL, Fatal) << "No Camera3StreamConfig is found for JPEG"; + + 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(unsortedConfigs.size()); + + /* + * 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 auto &nv12Largest = nv12Configs.back(); + + /* + * 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; + const Size &nv12LargestSize = nv12Largest->config.size; + + if (nv12LargestSize < nv12SizeForJpeg) { + LOG(HAL, Debug) << "Insert " << jpegConfig->config.toString(); + sortedConfigs.push_back(std::move(*jpegConfig)); + jpegConfig = nullptr; + } + } + + LOG(HAL, Debug) << "Insert " << nv12Largest->config.toString(); + sortedConfigs.push_back(*nv12Largest); + nv12Configs.pop_back(); + + if (nv12Configs.empty()) + formatToConfigs.erase(nv12It); + } + + /* 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 = nullptr; + } + + /* + * Put configurations with different formats and larger resolutions + * earlier. + */ + while (!formatToConfigs.empty()) { + for (auto it = formatToConfigs.begin(); it != formatToConfigs.end();) { + auto &configs = it->second; + LOG(HAL, Debug) << "Insert " << configs.back()->config.toString(); + sortedConfigs.push_back(*configs.back()); + configs.pop_back(); + + if (configs.empty()) + it = formatToConfigs.erase(it); + else + it++; + } + } + + ASSERT(sortedConfigs.size() == unsortedConfigs.size()); + + unsortedConfigs = sortedConfigs; +} +} /* namespace */ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags) @@ -1356,6 +1461,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfigs[index].streams.push_back({ jpegStream, type }); } + sortCamera3StreamConfigs(streamConfigs, jpegStream); for (const auto &streamConfig : streamConfigs) { config_->addConfiguration(streamConfig.config);