From patchwork Thu Aug 5 13:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13210 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 75037C3238 for ; Thu, 5 Aug 2021 13:45:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4368823; Thu, 5 Aug 2021 15:45:46 +0200 (CEST) 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="A6cmYA7F"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0E6E6026D for ; Thu, 5 Aug 2021 15:45:43 +0200 (CEST) Received: by mail-pj1-x1031.google.com with SMTP id u5-20020a17090ae005b029017842fe8f82so278242pjy.0 for ; Thu, 05 Aug 2021 06:45:43 -0700 (PDT) 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=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=; b=A6cmYA7F8/m5lCGGZHpwTajTU0x8ozNzKkppm82L5vASsOiL284Cri1Y6efmANxQEK BnnVBJA0Ciwe9OcP6G510My11p9Xy0D2/bfN9y/F+7yiKw1ZJAulcYy3VuxZxsHT0KlR uw3UX0DY0ATFcpbEOUYZjV0UiB1Bz5NihlDDw= 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=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=; b=JyHl9XdceMIYNcPkKXTK6wVZJLc18kdbMssAc3fi6I068BIWHhaKtrVxpSuHh8kM7t WhiBHVkuNcAXOWJMO6J+NCbVb3smH+yIXuyGQeSZXEH8rI3vXoOfdprRAl+/5D2bPx1z vvkNgmW+9RmrfyMveE+P2BQgrTe8wk6hTc9piFEs+V6iT2YQ83qsgCv8WW38l/Qy/2ME HxSfDHoNHDjX9wHRjEM1dBowyEBQGET6ip1it7qzJ72/a+iHDz83ojrSsT67Cmn/NfL7 KecSrguO8zDJoJqjl7hIdzx+FVDZLX7zJLGN8cBUh/wSoW37W0TNXLjWr3lRHItTQGr1 3Q5A== X-Gm-Message-State: AOAM531wXkw0uswl9/uU42s9EAG77LDxpnxnf+V6p9gp6ImNtFBbzNZy 5FYwyoGib2dDpdhzjYoAF+ueLe2G9I+bwg== X-Google-Smtp-Source: ABdhPJwZLTpiLFnPesrUgKx4WeM4xA4S4bJECNkk5QQmDfQOXMQBaPdnk1Qhmwm3yPBkS9zhMIYgHQ== X-Received: by 2002:a63:d106:: with SMTP id k6mr26941pgg.234.1628171142041; Thu, 05 Aug 2021 06:45:42 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:490b:61c8:a52a:e6eb]) by smtp.gmail.com with ESMTPSA id b8sm6029381pjo.51.2021.08.05.06.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 06:45:41 -0700 (PDT) From: Hirokazu Honda 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 Subject: [libcamera-devel] [PATCH 3/3] android: camera_device: Configure one stream for identical stream requests 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" An Android HAL client may request identical stream requests. It is redundant that a native camera device produces a separate stream for each of the identical requests. Configure camera one stream configuration for the identical stream requests. Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 27 ++++++++++++++++++++++----- src/android/camera_device.h | 3 +-- src/android/camera_stream.cpp | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 2466122d..68b2840c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -618,14 +618,32 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) continue; } + /* This stream will be produced by hardware. */ + stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; + + /* + * If they are the same capture request, associate with the same + * CameraStream. + */ + auto iter = std::find_if( + streamConfigs.begin(), streamConfigs.end(), + [size, format](const Camera3StreamConfig &streamConfig) { + return streamConfig.config.size == size && + streamConfig.config.pixelFormat == format; + }); + if (iter != streamConfigs.end()) { + /* Add usage to copy the buffer in streams[0] to stream. */ + iter->streams[0].stream->usage |= GRALLOC_USAGE_SW_READ_OFTEN; + stream->usage |= GRALLOC_USAGE_SW_WRITE_OFTEN; + iter->streams.push_back({ stream, CameraStream::Type::Mapped }); + continue; + } + Camera3StreamConfig streamConfig; streamConfig.streams = { { stream, CameraStream::Type::Direct } }; streamConfig.config.size = size; streamConfig.config.pixelFormat = format; streamConfigs.push_back(std::move(streamConfig)); - - /* This stream will be produced by hardware. */ - stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; } /* Now handle the MJPEG streams, adding a new stream if required. */ @@ -1095,12 +1113,11 @@ void CameraDevice::requestComplete(Request *request) resultMetadata = std::make_unique(0, 0); } - /* Handle any JPEG compression. */ for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { CameraStream *cameraStream = static_cast(buffer.stream->priv); - if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) + if (cameraStream->type() == CameraStream::Type::Direct) continue; FrameBuffer *src = request->findBuffer(cameraStream->stream()); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index cbc71be4..c5f96d32 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -48,6 +48,7 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } + const CameraCapabilities *capabilties() const { return &capabilities_; } const std::shared_ptr &camera() const { return camera_; } const std::string &maker() const { return maker_; } @@ -63,8 +64,6 @@ public: int processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request); - libcamera::PixelFormat toPixelFormat(int format) const; - protected: std::string logPrefix() const override; diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 8c02cb43..d880cc18 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -8,6 +8,7 @@ #include "camera_stream.h" #include "camera_buffer.h" +#include "camera_capabilities.h" #include "camera_device.h" #include "camera_metadata.h" #include "jpeg/post_processor_jpeg.h" @@ -62,7 +63,7 @@ int CameraStream::configure() { if (type_ == Type::Internal || type_ == Type::Mapped) { const PixelFormat outFormat = - cameraDevice_->toPixelFormat(camera3Stream_->format); + cameraDevice_->capabilties()->toPixelFormat(camera3Stream_->format); StreamConfiguration output = configuration(); output.pixelFormat = outFormat; switch (outFormat) {