{"id":13210,"url":"https://patchwork.libcamera.org/api/patches/13210/?format=json","web_url":"https://patchwork.libcamera.org/patch/13210/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210805134530.825065-4-hiroh@chromium.org>","date":"2021-08-05T13:45:30","name":"[libcamera-devel,3/3] android: camera_device: Configure one stream for identical stream requests","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6d506e9f6b3afe2e16d55486050357beb2d6e048","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13210/mbox/","series":[{"id":2307,"url":"https://patchwork.libcamera.org/api/series/2307/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2307","date":"2021-08-05T13:45:27","name":"android: Request one stream for identica stream requests","version":1,"mbox":"https://patchwork.libcamera.org/series/2307/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13210/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13210/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 75037C3238\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 Aug 2021 13:45:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4368823;\n\tThu,  5 Aug 2021 15:45:46 +0200 (CEST)","from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com\n\t[IPv6:2607:f8b0:4864:20::1031])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C0E6E6026D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Aug 2021 15:45:43 +0200 (CEST)","by mail-pj1-x1031.google.com with SMTP id\n\tu5-20020a17090ae005b029017842fe8f82so278242pjy.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 05 Aug 2021 06:45:43 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:490b:61c8:a52a:e6eb])\n\tby smtp.gmail.com with ESMTPSA id\n\tb8sm6029381pjo.51.2021.08.05.06.45.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 05 Aug 2021 06:45:41 -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=\"A6cmYA7F\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=;\n\tb=A6cmYA7F8/m5lCGGZHpwTajTU0x8ozNzKkppm82L5vASsOiL284Cri1Y6efmANxQEK\n\tBnnVBJA0Ciwe9OcP6G510My11p9Xy0D2/bfN9y/F+7yiKw1ZJAulcYy3VuxZxsHT0KlR\n\tuw3UX0DY0ATFcpbEOUYZjV0UiB1Bz5NihlDDw=","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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=;\n\tb=JyHl9XdceMIYNcPkKXTK6wVZJLc18kdbMssAc3fi6I068BIWHhaKtrVxpSuHh8kM7t\n\tWhiBHVkuNcAXOWJMO6J+NCbVb3smH+yIXuyGQeSZXEH8rI3vXoOfdprRAl+/5D2bPx1z\n\tvvkNgmW+9RmrfyMveE+P2BQgrTe8wk6hTc9piFEs+V6iT2YQ83qsgCv8WW38l/Qy/2ME\n\tHxSfDHoNHDjX9wHRjEM1dBowyEBQGET6ip1it7qzJ72/a+iHDz83ojrSsT67Cmn/NfL7\n\tKecSrguO8zDJoJqjl7hIdzx+FVDZLX7zJLGN8cBUh/wSoW37W0TNXLjWr3lRHItTQGr1\n\t3Q5A==","X-Gm-Message-State":"AOAM531wXkw0uswl9/uU42s9EAG77LDxpnxnf+V6p9gp6ImNtFBbzNZy\n\t5FYwyoGib2dDpdhzjYoAF+ueLe2G9I+bwg==","X-Google-Smtp-Source":"ABdhPJwZLTpiLFnPesrUgKx4WeM4xA4S4bJECNkk5QQmDfQOXMQBaPdnk1Qhmwm3yPBkS9zhMIYgHQ==","X-Received":"by 2002:a63:d106:: with SMTP id k6mr26941pgg.234.1628171142041; \n\tThu, 05 Aug 2021 06:45:42 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  5 Aug 2021 22:45:30 +0900","Message-Id":"<20210805134530.825065-4-hiroh@chromium.org>","X-Mailer":"git-send-email 2.32.0.554.ge1b32706d8-goog","In-Reply-To":"<20210805134530.825065-1-hiroh@chromium.org>","References":"<20210805134530.825065-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/3] android: camera_device: Configure one\n\tstream for identical stream requests","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"An Android HAL client may request identical stream requests. It is\nredundant that a native camera device produces a separate stream for\neach of the identical requests.\nConfigure camera one stream configuration for the identical stream\nrequests.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_device.cpp | 27 ++++++++++++++++++++++-----\n src/android/camera_device.h   |  3 +--\n src/android/camera_stream.cpp |  3 ++-\n 3 files changed, 25 insertions(+), 8 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 2466122d..68b2840c 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -618,14 +618,32 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n \t\t\tcontinue;\n \t\t}\n \n+\t\t/* This stream will be produced by hardware. */\n+\t\tstream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE;\n+\n+\t\t/*\n+\t\t * If they are the same capture request, associate with the same\n+\t\t * CameraStream.\n+\t\t */\n+\t\tauto iter = std::find_if(\n+\t\t\tstreamConfigs.begin(), streamConfigs.end(),\n+\t\t\t[size, format](const Camera3StreamConfig &streamConfig) {\n+\t\t\t\treturn streamConfig.config.size == size &&\n+\t\t\t\t       streamConfig.config.pixelFormat == format;\n+\t\t\t});\n+\t\tif (iter != streamConfigs.end()) {\n+\t\t\t/* Add usage to copy the buffer in streams[0] to stream. */\n+\t\t\titer->streams[0].stream->usage |= GRALLOC_USAGE_SW_READ_OFTEN;\n+\t\t\tstream->usage |= GRALLOC_USAGE_SW_WRITE_OFTEN;\n+\t\t\titer->streams.push_back({ stream, CameraStream::Type::Mapped });\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tCamera3StreamConfig streamConfig;\n \t\tstreamConfig.streams = { { stream, CameraStream::Type::Direct } };\n \t\tstreamConfig.config.size = size;\n \t\tstreamConfig.config.pixelFormat = format;\n \t\tstreamConfigs.push_back(std::move(streamConfig));\n-\n-\t\t/* This stream will be produced by hardware. */\n-\t\tstream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE;\n \t}\n \n \t/* Now handle the MJPEG streams, adding a new stream if required. */\n@@ -1095,12 +1113,11 @@ void CameraDevice::requestComplete(Request *request)\n \t\tresultMetadata = std::make_unique<CameraMetadata>(0, 0);\n \t}\n \n-\t/* Handle any JPEG compression. */\n \tfor (camera3_stream_buffer_t &buffer : descriptor.buffers_) {\n \t\tCameraStream *cameraStream =\n \t\t\tstatic_cast<CameraStream *>(buffer.stream->priv);\n \n-\t\tif (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB)\n+\t\tif (cameraStream->type() == CameraStream::Type::Direct)\n \t\t\tcontinue;\n \n \t\tFrameBuffer *src = request->findBuffer(cameraStream->stream());\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex cbc71be4..c5f96d32 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -48,6 +48,7 @@ public:\n \n \tunsigned int id() const { return id_; }\n \tcamera3_device_t *camera3Device() { return &camera3Device_; }\n+\tconst CameraCapabilities *capabilties() const { return &capabilities_; }\n \tconst std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }\n \n \tconst std::string &maker() const { return maker_; }\n@@ -63,8 +64,6 @@ public:\n \tint processCaptureRequest(camera3_capture_request_t *request);\n \tvoid requestComplete(libcamera::Request *request);\n \n-\tlibcamera::PixelFormat toPixelFormat(int format) const;\n-\n protected:\n \tstd::string logPrefix() const override;\n \ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex 8c02cb43..d880cc18 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -8,6 +8,7 @@\n #include \"camera_stream.h\"\n \n #include \"camera_buffer.h\"\n+#include \"camera_capabilities.h\"\n #include \"camera_device.h\"\n #include \"camera_metadata.h\"\n #include \"jpeg/post_processor_jpeg.h\"\n@@ -62,7 +63,7 @@ int CameraStream::configure()\n {\n \tif (type_ == Type::Internal || type_ == Type::Mapped) {\n \t\tconst PixelFormat outFormat =\n-\t\t\tcameraDevice_->toPixelFormat(camera3Stream_->format);\n+\t\t\tcameraDevice_->capabilties()->toPixelFormat(camera3Stream_->format);\n \t\tStreamConfiguration output = configuration();\n \t\toutput.pixelFormat = outFormat;\n \t\tswitch (outFormat) {\n","prefixes":["libcamera-devel","3/3"]}