From patchwork Thu Feb 4 10:05:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11143 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 049DFBD162 for ; Thu, 4 Feb 2021 10:06:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C45286142D; Thu, 4 Feb 2021 11:05:59 +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="oQLd+yoN"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B556461438 for ; Thu, 4 Feb 2021 11:05:58 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id l18so1495794pji.3 for ; Thu, 04 Feb 2021 02:05:58 -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=efVFGRlmisrEE/b5fPi2T6th4c/o9G0mdKmW6grdBQg=; b=oQLd+yoNW39WURWHzc5JbuBc9jOfCg/hNVOPuHiCqEoPgTx4d1SB2Te+v1UuaLr6QK b3hxGhNVU/86JKijyV52NwEFPTZbPHVs9QgGSUKhKVMkO/PFZsl2Td7HoRejxPcLRIMv I1N2OSsIF7zzGJLxpHsGLkNlxJcTC9NY+Zsn0= 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=efVFGRlmisrEE/b5fPi2T6th4c/o9G0mdKmW6grdBQg=; b=uIgy7XImj1sAsdtfygliE/ERmnH8OkEgpBwZvQcicn/KvFF8cq9JvLT/3pzmItCz+Q MV/2Bzztxm2fZ4EwQbdXypyaJG+M6mpYcGatZeh7dSZy6HiY7FjL9Oun0vmrHLspOaEt o1JJ/HDabkCjAAb0K/+cjebh144Xu1ZZxgJI2koUK3IlWtUJ7W9LUXWUR8ZtbHtuFtMu VfKCNhmHuzM7mzJM0IsTtm+4Q66SSdYrGsuLOyx9jZBdNi+ilq7QpRc/2/E3Ufa33+MW KBMndYzER5tLE5YriNoVrC8A9WHJ2ICILZfPjWskuAIcjrp8CyraGJ1TR8PYU8TjLeTy Gn7A== X-Gm-Message-State: AOAM532jzbzSoJVbraF7hgJJaz2OhktvrTnN4IrvFmV0zaM5q4Lf9fvw qfvynTawFR6d2KVdXlnQmqZIdAUSgN6lTLQm X-Google-Smtp-Source: ABdhPJzn5/YFWLWLTJyvEy8zPtlx4CGuGTklpYveBU1/wIcJdvYMrF8i84TRsH9YIYA/Fc4THcTYEw== X-Received: by 2002:a17:90a:df46:: with SMTP id gy6mr7566701pjb.163.1612433157019; Thu, 04 Feb 2021 02:05:57 -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 j9sm5808418pgb.47.2021.02.04.02.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 02:05:56 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Feb 2021 10:05:40 +0000 Message-Id: <20210204100541.657503-6-hiroh@chromium.org> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog In-Reply-To: <20210204100541.657503-1-hiroh@chromium.org> References: <20210204100541.657503-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 5/6] android: camera_device: Introduce PostProcessorType 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: , Cc: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This introduces PostProcessorType. It tracks the required post processor for CameraStream. Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 80 +++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 12 deletions(-) -- 2.30.0.365.g02bc693789-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 93dfbcdb..a1ef07b6 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 "jpeg/post_processor_jpeg.h" +#include "yuv/post_processor_yuv.h" #include #include @@ -131,6 +132,17 @@ const std::map camera3FormatsMap = { }, }; +/* PostProcessorType represents a post processor class. + * None: No post processor + * Jpeg: Jpeg encoding post processor + * Yuv : Yuv post post processor. + */ +enum class PostProcessorType : uint8_t { + None = 0, + Jpeg = 1, + Yuv = 2, +}; + /* * \struct Camera3StreamConfig * \brief Data to store StreamConfiguration associated with camera3_stream(s) @@ -142,11 +154,16 @@ struct Camera3StreamConfig { struct Camera3Stream { Camera3Stream(camera3_stream_t *stream, CameraStream::Type type) : stream(stream), type(type) {} + Camera3Stream(camera3_stream_t *stream, CameraStream::Type type, + PostProcessorType postProcessorType) + : stream(stream), type(type), + postProcessorType(postProcessorType) {} std::string toString() const; camera3_stream_t *stream = nullptr; CameraStream::Type type = CameraStream::Type::Direct; + PostProcessorType postProcessorType = PostProcessorType::None; }; std::string toString() const; @@ -169,6 +186,15 @@ std::string Camera3StreamConfig::Camera3Stream::toString() const { os << "Mapped"; break; } + switch (postProcessorType) { + case PostProcessorType::None: + os << "None"; break; + case PostProcessorType::Jpeg: + os << "Jpeg"; break; + case PostProcessorType::Yuv: + os << "Yuv"; break; + } + return os.str(); } @@ -1554,6 +1580,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) /* Now handle the MJPEG streams, adding a new stream if required. */ if (jpegStream) { CameraStream::Type type; + PostProcessorType postProcessorType = PostProcessorType::None; int index = -1; /* Search for a compatible stream in the non-JPEG ones. */ @@ -1573,6 +1600,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) type = CameraStream::Type::Mapped; index = i; + postProcessorType = PostProcessorType::Jpeg; break; } @@ -1600,14 +1628,18 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) index = streamConfigs.size() - 1; } - streamConfigs[index].streams.push_back({ jpegStream, type }); + streamConfigs[index].streams.push_back( + { jpegStream, type, postProcessorType }); } sortCamera3StreamConfigs(streamConfigs, jpegStream); + + std::vector postProcessorTypes; for (const auto &streamConfig : streamConfigs) { config_->addConfiguration(streamConfig.config); for (auto &stream : streamConfig.streams) { + postProcessorTypes.push_back(stream.postProcessorType); streams_.emplace_back(this, stream.type, stream.stream, config_->size() - 1); stream.stream->priv = static_cast(&streams_.back()); @@ -1647,21 +1679,46 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) * StreamConfiguration and set the number of required buffers in * the Android camera3_stream_t. */ - for (CameraStream &cameraStream : streams_) { + for (unsigned int i = 0; i < streams_.size(); ++i) { + CameraStream &cameraStream = streams_[i]; std::unique_ptr postProcessor; - if (cameraStream.type() == CameraStream::Type::Internal || - cameraStream.type() == CameraStream::Type::Mapped) { + switch(postProcessorTypes[i]) { + case PostProcessorType::None: + break; + case PostProcessorType::Jpeg: postProcessor = std::make_unique(this); + break; + case PostProcessorType::Yuv: + postProcessor = std::make_unique(); + break; + } + + if (postProcessor) { + const auto &camera3Stream = cameraStream.camera3Stream(); + StreamConfiguration output; + switch (camera3Stream.format) { + case HAL_PIXEL_FORMAT_BLOB: + output.pixelFormat = formats::MJPEG; + break; + case HAL_PIXEL_FORMAT_YCbCr_420_888: + output.pixelFormat = formats::NV12; + break; + default: + LOG(HAL, Error) + << "Unexpected format: " + << utils::hex(camera3Stream.format); + break; + } - auto output = cameraStream.configuration(); - output.pixelFormat = formats::MJPEG; - postProcessor->configure(cameraStream.configuration(), - output); + output.size.width = camera3Stream.width; + output.size.height = camera3Stream.height; + ret = postProcessor->configure( + cameraStream.configuration(), output); if (ret) { - LOG(HAL, Error) << "Failed to configure " - << "PostProcessorJpeg"; + LOG(HAL, Error) + << "Failed to configure post processor"; return ret; } } @@ -1871,12 +1928,11 @@ void CameraDevice::requestComplete(Request *request) uint64_t timestamp = buffers.begin()->second->metadata().timestamp; resultMetadata = getResultMetadata(descriptor, timestamp); - /* Handle any JPEG compression. */ for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { CameraStream *cameraStream = static_cast(descriptor->buffers_[i].stream->priv); - if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) + if (cameraStream->type() == CameraStream::Type::Direct) continue; FrameBuffer *buffer = request->findBuffer(cameraStream->stream());