Show a patch.

GET /api/1.1/patches/10286/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 10286,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/10286/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10286/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20201028100134.3007829-1-hiroh@chromium.org>",
    "date": "2020-10-28T10:01:34",
    "name": "[libcamera-devel,RFC] android: camera_device: Reorder configurations given by a HAL client",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d5b3903f990d902cad3818abb3ef8b142ab688d5",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/1.1/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/10286/mbox/",
    "series": [
        {
            "id": 1427,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1427/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1427",
            "date": "2020-10-28T10:01:34",
            "name": "[libcamera-devel,RFC] android: camera_device: Reorder configurations given by a HAL client",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1427/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10286/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10286/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9CCA7C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Oct 2020 10:01:48 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0AEB662390;\n\tWed, 28 Oct 2020 11:01:48 +0100 (CET)",
            "from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com\n\t[IPv6:2607:f8b0:4864:20::1042])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 03A3462067\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Oct 2020 11:01:47 +0100 (CET)",
            "by mail-pj1-x1042.google.com with SMTP id gi3so2214572pjb.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Oct 2020 03:01:46 -0700 (PDT)",
            "from hiroh.tok.corp.google.com\n\t([2401:fa00:8f:2:de4a:3eff:fe7d:f78f])\n\tby smtp.gmail.com with ESMTPSA id\n\tt129sm5462526pfc.140.2020.10.28.03.01.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 28 Oct 2020 03:01:44 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"VPnBk5u3\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; h=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=osQIJntr8WSN03DZiuYvHMC87nWvx0zAzTYas9a7b9c=;\n\tb=VPnBk5u309rV4YmbRzQbyFPwyOeO6Xz0JR8Y/BmUJJyYa+SwKdhRXRckWgz8R0jek2\n\tSgSA/0Du9z5r6VGL+ziTXt6UIP/fd1vBsdyvOy6swfWl3KdwVfQ9nkHu2ttJKgZ00ktp\n\tmqcvnQn7BAVoftikoysdODt7s4ONVQHTW8RlE=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=osQIJntr8WSN03DZiuYvHMC87nWvx0zAzTYas9a7b9c=;\n\tb=AHgpZSTyhfSntR4TdfCCtWJ1UntGw5j4kpsdZT6/Namy4Xg/XhpXf+lkJqZf/x+b1E\n\tal2QPbKAA2JwCrxe8Q4Bs3Cfga27A0zuah26OOGx3RPL+PAQi6Uv/AF6majJWoOADEqP\n\tOO7L0EJSg7Ws0xNsl/PPZgHTNmPObuu/u6B7KM64TXRgIX26gUvywc1foFR9hqG5mm0G\n\thZgd8VJpIDFFrzbqHYnRBb5gbqGZJ69gHCL5PL8gnwqNsUCkx/ToygTQLtUCeEcH1Eg+\n\tVCyFCBNIXRSHjU4TuMLxmddYWlLtXuc8390IxLYgqt89hrJT4PVM24QVsnijI4tZZV8v\n\tnlpw==",
        "X-Gm-Message-State": "AOAM532Puok/lRcOgEnvG/idaFdaAEYlHXNUql57ELMqGC6o3lrv8+ey\n\tKjTJbLTFuOr4iDy0cM8WQi3Qa7pcRaa5Xw==",
        "X-Google-Smtp-Source": "ABdhPJzwHVZyFJWav73sElnuuKVuUQ3BuiWK/ontCCSVNCFxVBv6YYvbCtK0xj+JxnbvA8FjaVingA==",
        "X-Received": "by 2002:a17:90b:1085:: with SMTP id\n\tgj5mr6135216pjb.30.1603879305177; \n\tWed, 28 Oct 2020 03:01:45 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 28 Oct 2020 19:01:34 +0900",
        "Message-Id": "<20201028100134.3007829-1-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.29.0.rc2.309.g374f81d7ae-goog",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [RFC PATCH] android: camera_device: Reorder\n\tconfigurations given by a HAL client",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Reorder configurations given by a HAL client in configureStreams()\nso that CameraDevice and pipeline handlers can accept them as much\nas possible.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_device.cpp | 108 +++++++++++++++++++++++++++++++++-\n src/android/camera_device.h   |   3 +-\n 2 files changed, 109 insertions(+), 2 deletions(-)\n\n--\n2.29.0.rc2.309.g374f81d7ae-goog",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex ca60f51..eee7248 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -9,6 +9,7 @@\n #include \"camera_ops.h\"\n #include \"post_processor.h\"\n\n+#include <string.h>\n #include <sys/mman.h>\n #include <tuple>\n #include <vector>\n@@ -132,6 +133,16 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {\n\n LOG_DECLARE_CATEGORY(HAL)\n\n+void printStreamList(const camera3_stream_configuration_t& streamList) {\n+\tLOG(HAL, Error) << \"num_streams=\" << streamList.num_streams;\n+\tfor (unsigned int i = 0; i < streamList.num_streams; i++) {\n+\t\tconst auto* stream = streamList.streams[i];\n+\t\tLOG(HAL, Error) << i << \": width=\" << stream->width\n+\t\t\t\t<< \", height=\" << stream->height\n+\t\t\t\t<< \", format=\" << stream->format;\n+\t}\n+}\n+\n MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n \t\t\t\t\t int flags)\n {\n@@ -1188,7 +1199,7 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)\n \treturn requestTemplate->get();\n }\n\n-PixelFormat CameraDevice::toPixelFormat(int format)\n+PixelFormat CameraDevice::toPixelFormat(int format) const\n {\n \t/* Translate Android format code to libcamera pixel format. */\n \tauto it = formatsMap_.find(format);\n@@ -1201,6 +1212,97 @@ PixelFormat CameraDevice::toPixelFormat(int format)\n \treturn it->second;\n }\n\n+int CameraDevice::sortStreamConfig(camera3_stream_configuration_t* streamList) const\n+{\n+\tstd::map<uint32_t, std::vector<const camera3_stream_t*>> streamMap;\n+\tfor (unsigned int i = 0; i < streamList->num_streams; ++i) {\n+\t\tconst camera3_stream_t* stream = streamList->streams[i];\n+\t\tPixelFormat format = toPixelFormat(stream->format);\n+\t\tif (!format.isValid())\n+\t\t\treturn -EINVAL;\n+\t\tstreamMap[format.fourcc()].push_back(stream);\n+\t}\n+\tstd::vector<uint32_t> formats;\n+\tfor (auto& s: streamMap) {\n+\t\tformats.push_back(s.first);\n+\t\tauto& streams = s.second;\n+\t\t/* Sorted by resolution. Smaller is put first. */\n+\t\tstd::sort(streams.begin(), streams.end(),\n+\t\t\t  [](const camera3_stream_t* streamA,\n+\t\t\t     const camera3_stream_t* streamB) {\n+\t\t\t\t  if (streamA->width != streamB->width)\n+\t\t\t\t\t  return streamA->width < streamB->width;\n+\t\t\t\t  return streamA->height < streamB->height;\n+\t\t\t  });\n+\t}\n+\n+\tif (streamMap.find(formats::MJPEG) != streamMap.end() &&\n+\t    streamMap[formats::MJPEG].size() > 1) {\n+\t\tLOG(HAL, Error) << \"Multiple JPEG streams are not supported\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tstd::vector<const camera3_stream_t*> sortedStreams;\n+\t/*\n+\t * NV12 is the most prioritized format. Put the configuration with NV12\n+\t * and the largest resolution first.\n+\t */\n+\tauto nv12StreamsIt = streamMap.find(formats::NV12);\n+\tif (nv12StreamsIt != streamMap.end()) {\n+\t\tauto& nv12Streams = nv12StreamsIt->second;\n+\t\tconst camera3_stream_t* nv12Stream = nv12Streams.back();\n+\t\tsortedStreams.push_back(nv12Stream);\n+\t\tnv12Streams.pop_back();\n+\t}\n+\n+\t/*\n+\t * If JPEG is there, then put the JPEG configuration second and a\n+\t * configuration whose specified stream the JPEG is encoded from third\n+\t * if there is.\n+\t */\n+\tauto jpegStreamsIt = streamMap.find(formats::MJPEG);\n+\tif (jpegStreamsIt != streamMap.end()) {\n+\t\tauto& jpegStreams = jpegStreamsIt->second;\n+\t\tconst camera3_stream_t* jpegStream = jpegStreams[0];\n+\t\tsortedStreams.push_back(jpegStream);\n+\t\tstreamMap.erase(jpegStreamsIt);\n+\t\tif (nv12StreamsIt != streamMap.end()) {\n+\t\t\tauto& nv12Streams = nv12StreamsIt->second;\n+\t\t\tauto nv12StreamForJpegIt =\n+\t\t\t\tstd::find_if(nv12Streams.begin(),\n+\t\t\t\t\t     nv12Streams.end(),\n+\t\t\t\t\t     [&jpegStream](const auto* nv12Stream) {\n+\t\t\t\t\t\t     return nv12Stream->width == jpegStream->width && nv12Stream->height == jpegStream->height;\n+\t\t\t\t\t     });\n+\t\t\tif (nv12StreamForJpegIt != nv12Streams.end()) {\n+\t\t\t\tsortedStreams.push_back(*nv12StreamForJpegIt);\n+\t\t\t\tnv12Streams.erase(nv12StreamForJpegIt);\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Put configurations with different formats and larger resolutions\n+\t * earlier.\n+\t */\n+\twhile (!streamMap.empty()) {\n+\t\tfor (auto it = streamMap.begin(); it != streamMap.end();) {\n+\t\t\tauto& streams = it->second;\n+\t\t\tif (streams.empty()) {\n+\t\t\t\tit = streamMap.erase(it);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tsortedStreams.push_back(streams.back());\n+\t\t\tstreams.pop_back();\n+\t\t}\n+\t}\n+\n+\tassert(sortedStreams.size() == streamList->num_streams);\n+\tmemcpy(streamList->streams, sortedStreams.data(),\n+\t       sizeof(camera3_stream_t*) * streamList->num_streams);\n+\treturn 0;\n+}\n+\n /*\n  * Inspect the stream_list to produce a list of StreamConfiguration to\n  * be use to configure the Camera.\n@@ -1225,6 +1327,10 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \tstreams_.clear();\n \tstreams_.reserve(stream_list->num_streams);\n\n+\tprintStreamList(*stream_list);\n+\tsortStreamConfig(stream_list);\n+\tprintStreamList(*stream_list);\n+\n \t/* First handle all non-MJPEG streams. */\n \tcamera3_stream_t *jpegStream = nullptr;\n \tfor (unsigned int i = 0; i < stream_list->num_streams; ++i) {\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex fd08738..f8dc28b 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -104,7 +104,8 @@ private:\n \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n \tCameraMetadata *requestTemplatePreview();\n-\tlibcamera::PixelFormat toPixelFormat(int format);\n+\tlibcamera::PixelFormat toPixelFormat(int format) const;\n+\tint sortStreamConfig(camera3_stream_configuration_t* streamList) const;\n \tstd::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,\n \t\t\t\t\t\t\t  int64_t timestamp);\n\n",
    "prefixes": [
        "libcamera-devel",
        "RFC"
    ]
}