From patchwork Fri Dec 11 06:03:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10639 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 F3DE8BD80A for ; Fri, 11 Dec 2020 06:03:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C399F634A0; Fri, 11 Dec 2020 07:03:25 +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="dE6B2AqW"; dkim-atps=neutral Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E732D60321 for ; Fri, 11 Dec 2020 07:03:23 +0100 (CET) Received: by mail-pg1-x544.google.com with SMTP id w4so6389350pgg.13 for ; Thu, 10 Dec 2020 22:03:23 -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=pvAznWDlRj1L7vV1SzIcC53gifNN4iz5OzO2gNFdbFk=; b=dE6B2AqWWsYFIB4blLHBNzXRIwrCiNpFFyi4XT9xo0Zpg6M7/GrGIfoZcBFXXMRwdU LmOH+AdgjqY5eaMoCRMR8YHcyDs2EeKycvNJTm1SCNQsmYFUr1erO79XHQu/1hX76qlD NUb7znjS1/BfeubKn9O3ftOiqy4zo7SCoyV7c= 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=pvAznWDlRj1L7vV1SzIcC53gifNN4iz5OzO2gNFdbFk=; b=tF1TK0jmKWZeRPUKkV7AW+/XK1y5EhJ1ZfmqG4TqWU9EUtLr+DHmJUK6sSAWMl0H/+ gnoYwWmYb3k2muDaKY59f/IIiNk53kUClLFTMarYlQG0YpQlsbWKfzBJuea6hHxLhntZ Nbn4vxSG3gRaN+1mdYu/VxO9desK9Dk5UvOlCX0a6kps650uD+8OA10uD6jCFdSO2avV tmKW8iOvQGKrn+KXcgvhBQareGGSQ4rL5misglJcSTZ5uTKEqVKyzUedzbx4p2R9mwih y6D+ViqXsa/a/C+WFyOs/0Hly6j7vIgE6xgePB73E4FNceuz9kGpYIUV29uhN9/c2XuR Bl8Q== X-Gm-Message-State: AOAM530n1XCMWyEXpyx72hPQZ1Si3d7rt1H3yDpLs47psw99KAXZnt4u Or6IW1Zh5q+Xe6AQ/4CplVBrmcG9r6CJ8g== X-Google-Smtp-Source: ABdhPJwH10M1uvVxHoEJmxdExAfxHIGPuyvSLb4wZeckKCkxM+LGxzUXLCY8fc2OYQiEFWheKjgj5Q== X-Received: by 2002:aa7:93cf:0:b029:19d:e287:b02b with SMTP id y15-20020aa793cf0000b029019de287b02bmr817386pff.66.1607666602006; Thu, 10 Dec 2020 22:03:22 -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 m77sm9207503pfd.105.2020.12.10.22.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 22:03:21 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 06:03:13 +0000 Message-Id: <20201211060315.2637333-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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..58ff329c 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 associated 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 06:03:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10640 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 84DB1BD80A for ; Fri, 11 Dec 2020 06:03:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 537FB67E4D; Fri, 11 Dec 2020 07:03:27 +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="PkiZ/00t"; dkim-atps=neutral Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 665FF6346D for ; Fri, 11 Dec 2020 07:03:26 +0100 (CET) Received: by mail-pj1-x1044.google.com with SMTP id j13so1792496pjz.3 for ; Thu, 10 Dec 2020 22:03:26 -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=NGAC1T7SVkfHxXdFPBDLMTozdyzAw8HtVP7RP2f4nSI=; b=PkiZ/00tPmYyMVQBi8uK/a5uyNf5N3b799ACMuTE3KbU8+3jZEszUZVkFK5BW+gwWn cvV19MBBnqj2rDDLCghm/GFaffBl2c07S8Zb3RZ081IczP/GZ+FAvE23GoBghykJAQDT 4LYr6GnfHuBmtwVsFArxIhPabbj3+5Q/gofGo= 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=NGAC1T7SVkfHxXdFPBDLMTozdyzAw8HtVP7RP2f4nSI=; b=mxIxdFS6p884XwWNqYJc39qxVd4+0/c29JHUSGOv2gfNZfsAmbVPO0fY6LH58o/lk8 PoX086qRbfhnqw9fvYYtAIy36YXAoy2EDbK514hotUID6iOdp7BD2sxCC7p++GMT6YT6 4kBaqYeEd2hKFekgxJTmvCpFCis57wQ2qArX4rlWorvnqAZ/KqwvuaGS7oW41qQNZ4TM kxsPpBTG4UgdBOTjNtpDX8hPkrf9+gGd7AWQjpcookoZHTtoTaT9PfDmvQi0Rvie//YG aPeXWt+5+lEd3+N2OYWHCFFVhThiFikLkKjPnV+Byi0ZxzJ1uZVZSGcEdJpg28OAwBET KfjQ== X-Gm-Message-State: AOAM531//xmN95X1RBtVUFidXNU0ETW4R2h+LsWuDD8052l1Zbgmzx4u g9fpE9qyLQXe+ttVUid9wcjg6t7MjE3lE1J3 X-Google-Smtp-Source: ABdhPJxlcjgoO0dysUQa0erUvUBcmdZS5MbwXOYCBeN5FiqqXzWFZUsv0GWrvIfzu/j77EA11c3sCQ== X-Received: by 2002:a17:90a:2a83:: with SMTP id j3mr11767822pjd.84.1607666604533; Thu, 10 Dec 2020 22:03:24 -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 m77sm9207503pfd.105.2020.12.10.22.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 22:03:23 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 06:03:14 +0000 Message-Id: <20201211060315.2637333-2-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201211060315.2637333-1-hiroh@chromium.org> References: <20201211060315.2637333-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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 58ff329c..5e245298 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 06:03:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10641 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 D4E8FBD80A for ; Fri, 11 Dec 2020 06:03:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A1EAD63500; Fri, 11 Dec 2020 07:03:29 +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="N/UEshDD"; 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 2DCB660321 for ; Fri, 11 Dec 2020 07:03:28 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id s2so4061514plr.9 for ; Thu, 10 Dec 2020 22:03:28 -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=QVkqWTnF3ukMztvLa3iQb5rnYDzJ7Tby8gsrhy1FkvU=; b=N/UEshDDKIgA1HvLcFTGNM+vlmfN/JKXmCB8a977vdHivjvrG+UQLDPYnJUYqwrID2 7w8W0Rray7UV6kRV83BHot+xHNglPrp+HvZ8M8TJukUFHPnbicrSDR3UlXVZ6zHSNPyk kV5bpqLvH5EoXMFcso4URWExECuT1kK6kXAXk= 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=QVkqWTnF3ukMztvLa3iQb5rnYDzJ7Tby8gsrhy1FkvU=; b=OTO+hZ9fNqQ8zpJO7ziRskEKFTfBWQgX6YyilHNBSI4GZaub9ThsvnZ7uo4X4yhTSN E4++l42tehtN6sVC7ngOaUB2C/AlXVL/PWSnXRYpndaxBVKIssvfQdIAkIrKFbL3+va7 DVSttbX7sBEh9iurajEy5f5XF3irXtffKgJ4JkJtcou/aFO+ER070sDSMC6X76PyAeRV vCq1Yaiwl3eqSHa/TkDsNdn+ePHXi/h+lnT1aIZyMFNFBJA1Uyx6Jsf8ymz3x9zlFmLz IHZgTM5uE1/TDCyoPz5vmli/itxKN8wqnt+WX+0mhUTNnAcDyGO80KCocp03aOf6G1l0 Ft7g== X-Gm-Message-State: AOAM532WEBQkCjFl19kzkTnTBetW3xzKEwy2ublFvjx40aAjB/SNMK+B Ld8VZW4/+GhaMnvcv5hHJVnGBBtIcSwILsNa X-Google-Smtp-Source: ABdhPJz4uoQU1nne90GbdyWgZACBouNzqpsOrajqEwECICQhZH+ein/cY2ffDlBHsJpTt0qi8oEYgA== X-Received: by 2002:a17:90a:4dcd:: with SMTP id r13mr11564157pjl.74.1607666606488; Thu, 10 Dec 2020 22:03:26 -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 m77sm9207503pfd.105.2020.12.10.22.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 22:03:25 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 11 Dec 2020 06:03:15 +0000 Message-Id: <20201211060315.2637333-3-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201211060315.2637333-1-hiroh@chromium.org> References: <20201211060315.2637333-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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: Jacopo Mondi --- 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 5e245298..a2c005af 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 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 = nullptr; + } + } + + LOG(HAL, Debug) << "Insert " << nv12Configs.back()->config.toString(); + sortedConfigs.push_back(*nv12Configs.back()); + 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);