From patchwork Mon Dec 7 08:42:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10588 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 82A07BDB1F for ; Mon, 7 Dec 2020 10:25:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4EE7B67E18; Mon, 7 Dec 2020 11:25:33 +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="JP2QLIrm"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CA4467E12 for ; Mon, 7 Dec 2020 11:25:32 +0100 (CET) Received: by mail-pf1-x433.google.com with SMTP id d2so5526348pfq.5 for ; Mon, 07 Dec 2020 02:25:32 -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=uL9kLwdJcM4nkkeSwEdQHHno8rfLImGJ6usEyAzyh0Y=; b=JP2QLIrmKaTMqNCrQmO5iGkvIxpjMQF2mQ+r0OJNTcCKwlDgJX/HsrFl2LnTkVyhWL /A6VGrnBvhSWfuQ6AkUrHo++JxdbftV/S4AQaTDgyu2Su0obr9ZS+fn6RkYJa0oYEKVF lE+0MSCNCdlYiK59tJpRqvATe0f4cMuxUcqD8= 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=uL9kLwdJcM4nkkeSwEdQHHno8rfLImGJ6usEyAzyh0Y=; b=SFe7SyVE5Th19RbAWLsojrPAQ7Fp9B8UQMGHgA5HDFl1C1+UELpddlZUD07EiG93DC Y9QnQaQKAsOd+G9gfAZkexnhEYO2rnnuWvhB0JCEuXjQv0QfL0UP3JyVlJyLcwzheGCl dT7qwPSZcRuWOmwPIFwzu1wM0xQo9PiPygM26KCtts0t9/CV9Z7q+VyLV1N6XakCJs/T tuPTUDeo6hx/kb0cILM/txyM764TJuErQX92lSXvrdNEbOVqNZyC3NsmYV/0fDSFvyBU Tyz2wnOf48P+cXYDSe13wpYTA1KFJU6X0DZj5DC6rMGDS5plu9vHaXmmwBfaWWFn9Lfd PvqQ== X-Gm-Message-State: AOAM530fQnbc5vJV7MtMwPIIsDKUiF0vofubT5MqNMoncQHLUY4kbeop YrKP7KxgzxOvkwMuYSYB9Y1gC/bFS6JwwUe3kBA= X-Google-Smtp-Source: ABdhPJzJp8zfdxq2UkOSYVrl59qQWUWOeml/GirHNYVDsm++y4RPaElY3bzZrjS93CUB0Yb3r9JQeg== X-Received: by 2002:a62:1ec7:0:b029:197:e012:19b with SMTP id e190-20020a621ec70000b0290197e012019bmr14791399pfe.77.1607330552040; Mon, 07 Dec 2020 00:42:32 -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 22sm12772144pfn.190.2020.12.07.00.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 00:42:31 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 08:42:16 +0000 Message-Id: <20201207084218.2307410-1-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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. --- 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 Mon Dec 7 08:42:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10591 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 CCBCDBDB1F for ; Mon, 7 Dec 2020 10:46:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F49A67E16; Mon, 7 Dec 2020 11:46:30 +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="LhV6aHDd"; dkim-atps=neutral Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB5F967E12 for ; Mon, 7 Dec 2020 11:46:28 +0100 (CET) Received: by mail-oi1-x241.google.com with SMTP id s75so11837019oih.1 for ; Mon, 07 Dec 2020 02:46: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=XCfAms3h7myBvNieIr+PFbFvvDNnue+uTz5FCau7AXY=; b=LhV6aHDdp2sJw9gJRxKrdWQZV7CafCE9IjlCHWDwfPQZhAQCUF8bnda+SIbsF/HuZb 3MUmu6fEUrFTVEyb3xdAmt5wcB05NyU1VlUAVSaBArn9emUuG+Zpot5h2rfkaQ/Xtk1K ZXNdMvcUbqA0ElLC9kPJ4/kVVfmA26yjuFhGk= 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=XCfAms3h7myBvNieIr+PFbFvvDNnue+uTz5FCau7AXY=; b=rtMKGtGBb5SjqQ2ODu3DFkbF9XKnAfqcY503k3YGnVIn1x61VYHoyajuyAHMhJeBas mJuK1soVvNaaQQ+eI3iwue2YqATPLq3LSE28aiCDGUHjGySHbG8fpDEHHZoAXGc4b1xD Nk7m+Gbnlq5yrrbBbemZZhBwpMyQ33JOkOqOoc2zjByHQVZpL/n3x9PDMJ8zHUsUruW6 1jJ0ND4cB3m+iUgcVXjUDDp/fl02DCnyvkhk8I91h3IQyojudyece1bkbEpfiyfsNaJx YfJOZ8ScoyQUBMZmFwkMt5CNfv29t/ayW1/xaK2GVo6Fh7rGdNXgZRU03NYzUqfqcYuX dbSA== X-Gm-Message-State: AOAM530eQXG8zoOWphWjtck5AlFGLKo4Lxc4CiwsdiSnNuRwt9+/sc8+ 5yGXOn4+tJFnk3SyLq66TnfVOSX0x6pYRqTbTfc= X-Google-Smtp-Source: ABdhPJy+WtawKqbAPa8CyMyimbdNuv7Tjn4EMPabU6TUVI6jsXsn6bwv/5WcSpLN22fqfuvTbO4oyQ== X-Received: by 2002:a17:90a:882:: with SMTP id v2mr15783359pjc.36.1607330553681; Mon, 07 Dec 2020 00:42:33 -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 22sm12772144pfn.190.2020.12.07.00.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 00:42:33 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 08:42:17 +0000 Message-Id: <20201207084218.2307410-2-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201207084218.2307410-1-hiroh@chromium.org> References: <20201207084218.2307410-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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" This uses Camera3StreamConfig in CameraDevice::configureStreams(). --- 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 Mon Dec 7 08:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 10590 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 4DCE0BDB20 for ; Mon, 7 Dec 2020 10:44:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D9ED467E18; Mon, 7 Dec 2020 11:44:45 +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="Ll7gTIdc"; dkim-atps=neutral Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9971F67E12 for ; Mon, 7 Dec 2020 11:44:44 +0100 (CET) Received: by mail-oi1-x233.google.com with SMTP id d27so7364372oic.0 for ; Mon, 07 Dec 2020 02:44:44 -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=5B3+4fHuXABlXZmpKC3ZgA6+5KHCXp2gsSEH09n1+nQ=; b=Ll7gTIdcdNe3WHItA7XbpnZfvFedEjwM8knaA6LTnCHS4/HkMh+rQ6/n+8uVYw6tCr GDp6G95XK3BXkVyP1QLh5PY9JFHhh0lacwi+PQwmq9GqQnnDiEiUcd+bxStMrYZm7Lvm nXMH9BtwFOFTtIie8XjI4LdNhcgdoFqxbKcsI= 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=5B3+4fHuXABlXZmpKC3ZgA6+5KHCXp2gsSEH09n1+nQ=; b=iJdTXLo0BxMXG3mz9b75kY+0AAPeEP3+CfOgAoGHBnVtkyA1cG3inZm6Z52kGNRA6a BpUdexOommO4UoSJNH1E5gotSRHXDpOxMUQDCajVKksMX+qWZdlYlmtKvoiyk4zFtKb9 ZAXET38Io1F0nhzhUJ1a08aRPhp0erBgpktzF9N6EQeUVB9JZs+AfSliuEfclAc6zSMt jMYrOhMlg3GgCyqjfNzFg6O9o+Uf4dQwRNbMenUZAej34UCCgC0Im85P/2f1wzPraq0X fknG79tybO2QD51lgR3NHRzEPrGVcba13sKo7/zJfP7xv/VG1d5oZdLHinby+nO9ya7Y dTKw== X-Gm-Message-State: AOAM531Uli1fFt5y8AE8/z3hXaC48szF7jLsPlx21bGMPqJai6hWTjui oDD1WACKi69dGOJQsHau5G7/+poPnVZFE2ne9Ks= X-Google-Smtp-Source: ABdhPJzaJdalaesUQmPIlathtcSondTtnNKDtIvPKIUZ9AuReMDfqlk1WqdB3ee3Yu5n2c/8wwkWcA== X-Received: by 2002:a17:90a:e64e:: with SMTP id ep14mr9019778pjb.5.1607330555266; Mon, 07 Dec 2020 00:42:35 -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 22sm12772144pfn.190.2020.12.07.00.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 00:42:34 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 08:42:18 +0000 Message-Id: <20201207084218.2307410-3-hiroh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201207084218.2307410-1-hiroh@chromium.org> References: <20201207084218.2307410-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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. --- src/android/camera_device.cpp | 104 +++++++++++++++++++++++++++++++++- 1 file changed, 102 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..dcba4e7d 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,104 @@ struct Camera3StreamConfig { std::vector types; StreamConfiguration config; }; -} /* namespace */ -LOG_DECLARE_CATEGORY(HAL) +/* + * Reorder the configurations so that CameraDevice 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 unsortedStreamConfigs, + const camera3_stream_t *jpegStream) { + const size_t unsortedStreamConfigsSize = unsortedStreamConfigs.size(); + std::optional streamConfigForJpeg = std::nullopt; + if (jpegStream) { + for (auto it = unsortedStreamConfigs.begin(); + it != unsortedStreamConfigs.end(); it++) { + const auto &streams = it->streams; + if (std::find(streams.begin(), streams.end(), + jpegStream) != streams.end()) { + streamConfigForJpeg = *it; + unsortedStreamConfigs.erase(it); + break; + } + } + if (!streamConfigForJpeg) + LOG(HAL, Fatal) << "No Camera3StreamConfig is found for Jpeg"; + } + + std::map> formatToConfigs; + for (const auto &streamConfig : unsortedStreamConfigs) { + 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 sortedStreamConfigs; + sortedStreamConfigs.reserve(unsortedStreamConfigsSize); + /* + * NV12 is the most prioritized format. Put the configuration with NV12 + * and the largest resolution first. + */ + const auto nv12Stream = formatToConfigs.find(formats::NV12); + if (nv12Stream != formatToConfigs.end()) { + auto &nv12StreamConfigs = nv12Stream->second; + const Size &nv12LargestSize = nv12StreamConfigs.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 (streamConfigForJpeg && + streamConfigForJpeg->config.pixelFormat == formats::NV12) { + const Size &nv12SizeForJpeg = streamConfigForJpeg->config.size; + if (nv12LargestSize < nv12SizeForJpeg) { + sortedStreamConfigs.push_back(*streamConfigForJpeg); + streamConfigForJpeg = std::nullopt; + } + } + sortedStreamConfigs.push_back(nv12StreamConfigs.back()); + nv12StreamConfigs.pop_back(); + } + + /* If the configuration for JPEG is there, then put it. */ + if (streamConfigForJpeg) { + sortedStreamConfigs.push_back(*streamConfigForJpeg); + streamConfigForJpeg = std::nullopt; + } + + /* + * Put configurations with different formats and larger resolutions + * earlier. + */ + while (!formatToConfigs.empty()) { + for (auto it = formatToConfigs.begin(); it != formatToConfigs.end();) { + auto& streamConfigs = it->second; + if (streamConfigs.empty()) { + it = formatToConfigs.erase(it); + continue; + } + sortedStreamConfigs.push_back(streamConfigs.back()); + streamConfigs.pop_back(); + it++; + } + } + assert(sortedStreamConfigs.size() == unsortedStreamConfigsSize); + + return sortedStreamConfigs; +} +} /* namespace */ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags) @@ -1333,6 +1431,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) {