From patchwork Wed Jan 20 08:34:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10905 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 9053DC0F2A for ; Wed, 20 Jan 2021 08:34:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C4C8568178; Wed, 20 Jan 2021 09:34:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HvgQ1heE"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC81168174 for ; Wed, 20 Jan 2021 09:34:55 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id l12so16981456wry.2 for ; Wed, 20 Jan 2021 00:34:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8CsZbCNSoM5n/uECUpVfmsDnCu3jKktYa/VPQ0evMBI=; b=HvgQ1heES08ymj40Lr09kpTbmNZ4LyE4QfCwyu3dCvzW369Rtpw0706Rb06siZUTXc U9brRf4OK1cS4EM6IMM3hy8qGjIg/5Sb5kMSQQFaF+tf+qJEKbsqyQwGwSNDGTHTGzWS g+uEXrWumWUBkAMOGpZf29FpiniiE5VvpF8mzKBAqMGOIwYGEYDZ1Sx+1KiBAsGXhRUp oz9PnIMzlmbvNk3uCZHLaOOya1CC23S/9KQ27fQwzgQ8mz1Do4uvUEWv9BFiXQnsBM8T djtnoA+m0c1rj3dwsBH9XzNbkys7osOxptbss7Q12IeQsYitT+iOsGjdxjU/r84Y2mZx lJew== 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=8CsZbCNSoM5n/uECUpVfmsDnCu3jKktYa/VPQ0evMBI=; b=t3TTVqy3FvjXYc9clbXeI8D4lMppLECNwG6X4yPuEiNASsozWwnMUYEacEjhr1HLlf DOWwRZ0OI5gQUMrAtWD6Orzx0WSwjjlk/ng2zX6UrgPhY5gAm2wy3N4P19fefnKgQptO 4AglMW1qxLZOJp/PojPRcTSR8YmUWEJdLMP0mXGysn3MGO14TqgASWZ/FHY+aIaTmSqY 4OUM78qVaD9qMbYzPzcoou/EpmCmIDwZTFQZaEjWXXQuEevmCfaJ3vydDnfGAYfpqnlW JNBmqKxXCPP/0nEGpi1ktKdaEwO0mVWQ7wVJOhlwrgXqxpF+AdwgESmnJNEocYGBmmZ9 DFfA== X-Gm-Message-State: AOAM533vpkyb61S3WWEHyB7iePxMkTZSq6fAyUMwRPvHVluYrE29l29D PoYR3azU75UHEe5JKv/mF9Irv50ACqrWXQ== X-Google-Smtp-Source: ABdhPJyuyR9Dosczh3mi7Mj2Pdc2A+n3hD7RBaO2bCGgt8dBdVIU/VJ3akp0CGTF6k91lPKhcJ9MZQ== X-Received: by 2002:adf:ce90:: with SMTP id r16mr8217214wrn.100.1611131695213; Wed, 20 Jan 2021 00:34:55 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 33sm2809284wrn.35.2021.01.20.00.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:34:54 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jan 2021 08:34:45 +0000 Message-Id: <20210120083449.642418-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120083449.642418-1-naush@raspberrypi.com> References: <20210120083449.642418-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] pipeline: raspberrypi: Refactor stream configuration routine 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" Refactor the high/low resolution stream format and output selection routine. This change is in preparation of adding 1/4 resolution output for fast colour denoise. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index f121328ee9a9..e03bcb036f9f 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -624,52 +624,27 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) continue; } - if (i == maxIndex) { - /* ISP main output format. */ - V4L2VideoDevice *dev = data->isp_[Isp::Output0].dev(); - V4L2PixelFormat fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); - format.size = cfg.size; - format.fourcc = fourcc; - - ret = dev->setFormat(&format); - if (ret) - return -EINVAL; - - if (format.size != cfg.size || format.fourcc != fourcc) { - LOG(RPI, Error) - << "Failed to set format on ISP capture0 device: " - << format.toString(); - return -EINVAL; - } - - cfg.setStream(&data->isp_[Isp::Output0]); - data->isp_[Isp::Output0].setExternal(true); - } + /* The largest resolution gets routed to the ISP Output 0 node. */ + RPi::Stream *stream = (i == maxIndex) ? &data->isp_[Isp::Output0] : + &data->isp_[Isp::Output1]; - /* - * ISP second output format. This fallthrough means that if a - * second output stream has not been configured, we simply use - * the Output0 configuration. - */ - V4L2VideoDevice *dev = data->isp_[Isp::Output1].dev(); - format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); + V4L2PixelFormat fourcc = stream->dev()->toV4L2PixelFormat(cfg.pixelFormat); format.size = cfg.size; + format.fourcc = fourcc; - ret = dev->setFormat(&format); - if (ret) { + ret = stream->dev()->setFormat(&format); + if (ret) + return -EINVAL; + + if (format.size != cfg.size || format.fourcc != fourcc) { LOG(RPI, Error) - << "Failed to set format on ISP capture1 device: " - << format.toString(); - return ret; - } - /* - * If we have not yet provided a stream for this config, it - * means this is to be routed from Output1. - */ - if (!cfg.stream()) { - cfg.setStream(&data->isp_[Isp::Output1]); - data->isp_[Isp::Output1].setExternal(true); + << "Failed to set format on " << stream->name() + << " to " << format.toString(); + return -EINVAL; } + + cfg.setStream(stream); + stream->setExternal(true); } /* ISP statistics output format. */ From patchwork Wed Jan 20 08:34:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10906 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 66A27C0F2A for ; Wed, 20 Jan 2021 08:34:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 27A0668182; Wed, 20 Jan 2021 09:34:59 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="iNwfnctw"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D9AD460312 for ; Wed, 20 Jan 2021 09:34:56 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id u14so2024355wmq.4 for ; Wed, 20 Jan 2021 00:34:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H6uWx2Ho8qpRpkD8knmJwuY9KThGww4e7VlCQWcrh20=; b=iNwfnctwDDReQEnuPTm17r6z/qHMK0tkC6Tfw2d4ik1HNo++WdpBCSqxahd+xOq2fb mmWTw+GL3NxNLzv3tRIPxmxV7tZ5aPdKoyeX6EEdzqLeIVVexxh7GjsTP4c2LgxYQCtO MdbWc7o+5XvSPYbvPobAnJr9XGFWIaAh+jqSnFTfl9xuxwgXIa8fkc/QV8L6UThUbMbp iFv2YjHSUzu8HaX2EeHKbyk9kMe2i/pBPIsjKivjQAvrPHS4ezIWSeIKTd8tsJeICBZe KqcqF9VhjGL5DnonpP5FQhPbVN60NUZWcsf/r9kYsN2ub2rUHCCGiEs6imH39xvX6/1e srdA== 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=H6uWx2Ho8qpRpkD8knmJwuY9KThGww4e7VlCQWcrh20=; b=WRIMMFm5YAWwNp6zixbN4UVGNZFPy/HGMMbqWb4L+XyLx6jwC7Nwg6G0fr5xHoIQi2 k22uZITHRgu/qhCcNaWEmCFNF91BbIl7dr6uArOUe0Ect7995SkkI31CHrcte+C2lvD8 kAV9rBvki4iKzD1Fabod7qdMAfXeMwcdvJxTo1rvxEexXxyo/m9z5L7PkcBia0jLsTiq gHzJsxGNu0aZwhhMx35OHgPK6k2ACmmURMd4LTPmQtJ/B/N9ck3y0umVx5Rys7m9sEMH XAcfaoIqUYIb/xhkN1DIfcFU89R16sh24Vgtv1OOMt/wLsYTojg4QSSs4vTq8yNXGI8C QJ9Q== X-Gm-Message-State: AOAM530kXYWP5LJbH5gu7X8KW6OcZndPU4/gjbKfx8SPxGUJ1M8bKM4K uLXxlhl8cKSRUlOrbqTHYqA/w9vII3Gf1Q== X-Google-Smtp-Source: ABdhPJzAR5o6ow3rT/L5u0eothP9WnqFLniSylHtkgLGNe6AMLOkxW8w+UuGYSee/yB4D9+AQO2AQg== X-Received: by 2002:a1c:a145:: with SMTP id k66mr3218927wme.18.1611131696321; Wed, 20 Jan 2021 00:34:56 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 33sm2809284wrn.35.2021.01.20.00.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:34:55 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jan 2021 08:34:46 +0000 Message-Id: <20210120083449.642418-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120083449.642418-1-naush@raspberrypi.com> References: <20210120083449.642418-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] pipeline: raspberrypi: Set the ISP Output1 to 1/4 resolution if unused 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" In preparation for fast colour denoise, set the low resolution ISP output stream (Output1) to a 1/4 resolution of the application requested stream (Output0). This only happens if the application has not requested an additional YUV or RGB stream. We also constrain this 1/4 resolution to at most 1200 pixels in the largest dimension to avoid being too taxing on memory usage and system bandwidth. Also switch the default StreamRole::VideoRecording to YUV420 to allow fast colour denoise to run. Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e03bcb036f9f..282c4ba75d89 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -496,7 +496,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, case StreamRole::VideoRecording: fmts = data->isp_[Isp::Output0].dev()->formats(); - pixelFormat = formats::NV12; + pixelFormat = formats::YUV420; size = { 1920, 1080 }; bufferCount = 4; outCount++; @@ -608,6 +608,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * StreamConfiguration appropriately. */ V4L2DeviceFormat format; + bool output1Set = false; for (unsigned i = 0; i < config->size(); i++) { StreamConfiguration &cfg = config->at(i); @@ -632,6 +633,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) format.size = cfg.size; format.fourcc = fourcc; + LOG(RPI, Info) << "Setting " << stream->name() << " to a resolution of " + << format.toString(); + ret = stream->dev()->setFormat(&format); if (ret) return -EINVAL; @@ -645,6 +649,42 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) cfg.setStream(stream); stream->setExternal(true); + + if (i != maxIndex) + output1Set = true; + } + + /* + * If ISP::Output1 stream has not been requested by the application, we + * set it up for internal use now. This second stream will be used for + * fast colour denoise, and must be a quarter resolution of the ISP::Output0 + * stream. However, also limit the maximum size to 1200 pixels in the + * larger dimension, just to avoid being wasteful with buffer allocations + * and memory bandwidth. + */ + if (!output1Set) { + V4L2DeviceFormat output1Format = format; + constexpr unsigned int maxDimensions = 1200; + + output1Format.size = format.size / 2; + if (output1Format.size.width > maxDimensions) { + output1Format.size.height = maxDimensions * output1Format.size.height / + output1Format.size.width; + output1Format.size.height &= ~1; + output1Format.size.width = maxDimensions; + } else if (output1Format.size.height > maxDimensions) { + output1Format.size.width = maxDimensions * output1Format.size.width / + output1Format.size.height; + output1Format.size.width &= ~1; + output1Format.size.height = maxDimensions; + } + + LOG(RPI, Info) << "Setting ISP Output 1 (internal) to a resolution of " + << output1Format.toString(); + + ret = data->isp_[Isp::Output1].dev()->setFormat(&output1Format); + if (ret) + return -EINVAL; } /* ISP statistics output format. */ From patchwork Wed Jan 20 08:34:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10907 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 B2D4AC0F2A for ; Wed, 20 Jan 2021 08:35:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 807A06818A; Wed, 20 Jan 2021 09:35:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="EfAEAiJn"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E9D506817F for ; Wed, 20 Jan 2021 09:34:57 +0100 (CET) Received: by mail-wr1-x42c.google.com with SMTP id a12so22184951wrv.8 for ; Wed, 20 Jan 2021 00:34:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8+WE1NbwXZbetuH84QlaBUaemUMsSvDAmxHr0W24uLk=; b=EfAEAiJnsCMXaTOtzjLK44KG/wdQfKha//2TVE4ZZaQo3H5jR0m+rnOmFAVRarbbxE xoiyEUo5K818QJXWzsec9+JbU2C4L3DUwvE6hBjQriQR06QOTn1bdlwXR1sMzAZ0eNXc rOoTR/UVdtP67wy3an5OjCMWMu1jH6+K6Qh5jlSJ9OzpuTPBkGjP9uqK0nGd/02j3VWQ 1R4P171whVNW4HyjEKFPn18VMV1wEiWxuijF0TJhXDsdsrhRH36rWihY5m10XqTf+STf tse/gnXtj5YI+b84im2MLiOAgZoOaB8TI6uL1yD91zbbsQEH6k0gg7mwXA36vFYdf8zd YFjg== 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=8+WE1NbwXZbetuH84QlaBUaemUMsSvDAmxHr0W24uLk=; b=TbtKNW+2lti3GEvE24QcETKMWYU9i+1eix3qYt6wEH+rOZssz4FHh5jK4l3grPhAaD akv+RJGxGSVQYRCqBPduZFCfOdIN0Ia1wbi1qoZu6rZLd+ZatnZJL593vIg0AoQQXhjY yNuwDuxc4T/OW3cn+M5rnYUb0LI8bnj1V5ooTn0+MrWxmiWtYjD+rwbna35FhRc3zmLX V22hXlmbisuXfbjHIiny/Z/6n3PdFkyE7yv3SHCjGWmA5RUqGbKNQmC0XBKSLTW6RcqY 3uyGP4X+2iQstaC7E7Ysqb7oyCiAGwBH49Lpx+dVsTWKpfyCNCveXrYOS2NTmkbyA4w0 KYBg== X-Gm-Message-State: AOAM531mzjaTCIDvU+dyCRSD4IlsQviv5K/dfNO6t6uzwdFQYfKDGGwf h1O1csbtLJOXlXVs4Fo4TM3XEWt4E4NGXg== X-Google-Smtp-Source: ABdhPJwFCrhyvsVPozUgCdHKCCCq8aXejzgxiFlARaJ6jPWVO5NMRNGYqLh08X9UWFjNCTANipGudQ== X-Received: by 2002:a5d:4d8d:: with SMTP id b13mr7811426wru.415.1611131697455; Wed, 20 Jan 2021 00:34:57 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 33sm2809284wrn.35.2021.01.20.00.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:34:56 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jan 2021 08:34:47 +0000 Message-Id: <20210120083449.642418-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120083449.642418-1-naush@raspberrypi.com> References: <20210120083449.642418-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] uapi: raspberrypi: Update the bcm2835-isp header definition 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" Update the bcm2835-isp.h file with the latest version available in the downstream Raspberryp Pi linux repo. This change adds support for colour denoise processing, and the following downstream kernel changes must be available: https://github.com/raspberrypi/linux/pull/4069 https://github.com/raspberrypi/linux/pull/4083 The Raspberry Pi image must also be running the latest firmware, obtained by running rpi-update. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Acked-by: Kieran Bingham --- include/linux/bcm2835-isp.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/include/linux/bcm2835-isp.h b/include/linux/bcm2835-isp.h index 45abb681517e..94c3af947883 100644 --- a/include/linux/bcm2835-isp.h +++ b/include/linux/bcm2835-isp.h @@ -31,7 +31,8 @@ (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0007) #define V4L2_CID_USER_BCM2835_ISP_DPC \ (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0008) - +#define V4L2_CID_USER_BCM2835_ISP_CDN \ + (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0009) /* * All structs below are directly mapped onto the equivalent structs in * drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h @@ -46,7 +47,7 @@ */ struct bcm2835_isp_rational { __s32 num; - __s32 den; + __u32 den; }; /** @@ -140,7 +141,7 @@ struct bcm2835_isp_black_level { __u16 black_level_r; __u16 black_level_g; __u16 black_level_b; - __u8 pad_[2]; /* Unused */ + __u8 padding[2]; /* Unused */ }; /** @@ -175,6 +176,31 @@ struct bcm2835_isp_gamma { __u16 y[BCM2835_NUM_GAMMA_PTS]; }; +/** + * enum bcm2835_isp_cdn_mode - Mode of operation for colour denoise. + * + * @CDN_MODE_FAST: Fast (but lower quality) colour denoise + * algorithm, typically used for video recording. + * @CDN_HIGH_QUALITY: High quality (but slower) colour denoise + * algorithm, typically used for stills capture. + */ +enum bcm2835_isp_cdn_mode { + CDN_MODE_FAST = 0, + CDN_MODE_HIGH_QUALITY = 1, +}; + +/** + * struct bcm2835_isp_cdn - Colour denoise parameters set with the + * V4L2_CID_USER_BCM2835_ISP_CDN ctrl. + * + * @enabled: Enable colour denoise. + * @cdn_mode: Colour denoise operating mode (see enum &bcm2835_isp_cdn_mode) + */ +struct bcm2835_isp_cdn { + __u32 enabled; + __u32 mode; +}; + /** * struct bcm2835_isp_denoise - Denoise parameters set with the * V4L2_CID_USER_BCM2835_ISP_DENOISE ctrl. From patchwork Wed Jan 20 08:34:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10908 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 26C61C0F2B for ; Wed, 20 Jan 2021 08:35:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB26568186; Wed, 20 Jan 2021 09:35:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hyHbz7Kb"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 240C368181 for ; Wed, 20 Jan 2021 09:34:59 +0100 (CET) Received: by mail-wm1-x32b.google.com with SMTP id y187so2031160wmd.3 for ; Wed, 20 Jan 2021 00:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iQ91Dj6nDbxti4/IPz0u4olicXcOg/0dvJWfHEwzSnk=; b=hyHbz7KbPPIyVC45GOTeZ7PJxsCiWB6h7f5eGs6pN43jI9AWMtwyHmTUiCRYMK/RHY eBAHJJWaEDtM8a9EVvwzHE46ZF2Jmv2z8I383Fi7I38IMBD2QpeulNb9RV8ulhr9KY39 B4ruwZyqYKA7kBpA7iSJ3MkkJqsMpUCEgoyJrMngo933llR6xalA8PBApEF6WzbFw6pg /DmyvOkyfqsVMeJ/c/aHpL1Lm0An02D+Qj9fuVaWEK6XUYHQ0FKp2AAK+m6aC2ttkgIX RO0rOcf8hNQpEvuCfFZY3e/b4N44Erdnk/aljVeKPyh3wD8czQQ0KSDlX7cYtJ61J9Lt VBuQ== 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=iQ91Dj6nDbxti4/IPz0u4olicXcOg/0dvJWfHEwzSnk=; b=fhQWZK0fxQ/TF5oIFnC357KDjizVJWWQlaYK1dizmpjC5H3/LRH8qxOsy5K51jlSvm JZ7tSP4lq0zfM8UG9MXmAvfPzFJ2A7UYCb0yw4f0EI/1WoTcmo9VI5VOeJb/Lzpolf4l Eq447aDo9bqEh9sZWRpnDWgYGTAMtWvf1GH+uXCnboBTyg3rFdvD+wz1kX8BCYVPmquw UKcjt+CV1p9z0+Zt5fmVBWZz5l+PY1KLTgqcUKFY1QOMbWi0/f9s8LdOnJ4Ei2rJmv+M QcGinGWZItb3MylbS7V15oFvnhTDnV2KHgNA7adl83vXb8XAZUxSh4P6rrRFo6yJ0pkj jDqQ== X-Gm-Message-State: AOAM533epRU6u7pTyZMrdkz8BVWg3txlLLFXRGQoxDSVPDsbs6qF5Nv2 JUVC+P/Yj6/P2/3WoTXCnjUNf7H8SyONrg== X-Google-Smtp-Source: ABdhPJyVuiOrGvZ4oyMAp8RNK+EliQPSw/cv0sqYGUHYA3wNTLlv1UGd2Hg7JK9ulz15XI6QvlB0Gw== X-Received: by 2002:a1c:8095:: with SMTP id b143mr3121604wmd.71.1611131698550; Wed, 20 Jan 2021 00:34:58 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 33sm2809284wrn.35.2021.01.20.00.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:34:57 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jan 2021 08:34:48 +0000 Message-Id: <20210120083449.642418-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120083449.642418-1-naush@raspberrypi.com> References: <20210120083449.642418-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] ipa: raspberrypi: Add a DenoiseAlgorithm class to the Controller 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 denoise algorithm class will be used to pass in the user requested denoise operating mode to the controller. The existing Denoise controller will derive from this new DenoiseAlgorithm class. Add a denoise mode field in the denoise status metadata object for the IPA to use when configuring the ISP. Signed-off-by: Naushir Patuck --- .../controller/denoise_algorithm.hpp | 23 +++++++++++++++++++ src/ipa/raspberrypi/controller/rpi/sdn.cpp | 11 +++++++-- src/ipa/raspberrypi/controller/rpi/sdn.hpp | 5 +++- src/ipa/raspberrypi/controller/sdn_status.h | 1 + 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/ipa/raspberrypi/controller/denoise_algorithm.hpp diff --git a/src/ipa/raspberrypi/controller/denoise_algorithm.hpp b/src/ipa/raspberrypi/controller/denoise_algorithm.hpp new file mode 100644 index 000000000000..05b7d46dad85 --- /dev/null +++ b/src/ipa/raspberrypi/controller/denoise_algorithm.hpp @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * denoise.hpp - Denoise (spatial and colour) control algorithm interface + */ +#pragma once + +#include "algorithm.hpp" + +namespace RPiController { + +enum DenoiseMode { Off, Fast, HighQuality }; + +class DenoiseAlgorithm : public Algorithm +{ +public: + DenoiseAlgorithm(Controller *controller) : Algorithm(controller) {} + // A Denoise algorithm must provide the following: + virtual void SetMode(DenoiseMode mode) = 0; +}; + +} // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index aa82830b02b4..3a600e07b2f3 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited * * sdn.cpp - SDN (spatial denoise) control algorithm */ @@ -18,7 +18,7 @@ using namespace RPiController; #define NAME "rpi.sdn" Sdn::Sdn(Controller *controller) - : Algorithm(controller) + : DenoiseAlgorithm(controller), mode_(DenoiseMode::Fast) { } @@ -48,6 +48,7 @@ void Sdn::Prepare(Metadata *image_metadata) status.noise_constant = noise_status.noise_constant * deviation_; status.noise_slope = noise_status.noise_slope * deviation_; status.strength = strength_; + status.mode = mode_; image_metadata->Set("sdn.status", status); RPI_LOG("Sdn: programmed constant " << status.noise_constant << " slope " << status.noise_slope @@ -55,6 +56,12 @@ void Sdn::Prepare(Metadata *image_metadata) << status.strength); } +void Sdn::SetMode(DenoiseMode mode) +{ + // We only distinguish between off and all other modes. + mode_ = mode; +} + // Register algorithm with the system. static Algorithm *Create(Controller *controller) { diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.hpp b/src/ipa/raspberrypi/controller/rpi/sdn.hpp index 486c000d7b77..2371ce04163f 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.hpp @@ -7,12 +7,13 @@ #pragma once #include "../algorithm.hpp" +#include "../denoise_algorithm.hpp" namespace RPiController { // Algorithm to calculate correct spatial denoise (SDN) settings. -class Sdn : public Algorithm +class Sdn : public DenoiseAlgorithm { public: Sdn(Controller *controller = NULL); @@ -20,10 +21,12 @@ public: void Read(boost::property_tree::ptree const ¶ms) override; void Initialise() override; void Prepare(Metadata *image_metadata) override; + void SetMode(DenoiseMode mode) override; private: double deviation_; double strength_; + DenoiseMode mode_; }; } // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/sdn_status.h b/src/ipa/raspberrypi/controller/sdn_status.h index 871e0b62af1f..29f2a68aabff 100644 --- a/src/ipa/raspberrypi/controller/sdn_status.h +++ b/src/ipa/raspberrypi/controller/sdn_status.h @@ -16,6 +16,7 @@ struct SdnStatus { double noise_constant; double noise_slope; double strength; + unsigned int mode; }; #ifdef __cplusplus From patchwork Wed Jan 20 08:34:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10909 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 A51F5C0F2A for ; Wed, 20 Jan 2021 08:35:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C3D568188; Wed, 20 Jan 2021 09:35:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ohr+48li"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3070560312 for ; Wed, 20 Jan 2021 09:35:00 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id c128so2039074wme.2 for ; Wed, 20 Jan 2021 00:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ViC63ieoHqyOFUdYo8HZrN27zywpSAcoAyfde3DdBlI=; b=ohr+48li8UAyefkFeRhMpJ0Hv0f4RfXziOIzx/0J/uDnXC1J4sWKCmtMVp/1Hh9tAn qqVLLiroHrumal1xzOuuluKLOWiajDmQNQFmqGH/m8xT7JZqVtaWGr9EqQkMm8IrW8He /VuQ3zcaf6g/7RlzPb8fj5E4RFJDZBtn5oYTQ3umAHSvM45o/zDrfyfUdbD887NVS8k9 cb9Yc37U73vRudvq/3bEVJuLzVJ20CJXdeNrNkwS7RKu7eDtxXSxkZPe/puKr1wPGkli S31vBNn2gLHCFRX7Ie3JvFGFl0akQM2sJhAFVfrgBPiVjy+ie9OSXZvnRNhI7g0BxDSA sn/g== 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=ViC63ieoHqyOFUdYo8HZrN27zywpSAcoAyfde3DdBlI=; b=sKrRNTTHQNtAhrSDtYYdoSQvbxdpj5TmR58ZTXqR33cVH3Fl5K69ltFdbmp2pCI907 43glcji1a8UjdiPsJQ1XNNXAFFW81gDR6UaTjfeTaXkBCNSkT17X5sRBpJnfszzq+ycA CyER0k6i/eXdn+aJdjeANfw3tYOfG85WgkHlgXVmd7HFcTP6arwtm7eUmAP6gMDfjtL9 NWnvQ412E25T99cXKfMbWLRhZ5VTSmgoOevmjn0/feWMBwf6LTQpy/nUHzQ1tJmeVyFz vZbBF8ak92UXWfxd0jCi43I7zZ6x3LehdHr4H7LsiTLTjzEkSBSPnLHkI5jSHR8YXsk+ QNIA== X-Gm-Message-State: AOAM5333H7UgxiPcmWzqnnNLpr/WW3+Vh5chO/O64ygvKmOqSfQ67eb7 qcYMjmcOXiOAmTQoveA0TY0pxpZkXWs5Og== X-Google-Smtp-Source: ABdhPJxIT+6BfhIviWZCiNj/SZhIQYYFcmgjjd1wqPbGNixVJVEV+DMVL1jTG9cUUrl5n46Tm5jb/A== X-Received: by 2002:a7b:c1d7:: with SMTP id a23mr3186218wmj.149.1611131699714; Wed, 20 Jan 2021 00:34:59 -0800 (PST) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id 33sm2809284wrn.35.2021.01.20.00.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:34:58 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Jan 2021 08:34:49 +0000 Message-Id: <20210120083449.642418-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120083449.642418-1-naush@raspberrypi.com> References: <20210120083449.642418-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] ipa: raspberrypi: Handle control::NoiseReductionMode in the controller 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" The application provided noise reduction mode gets passed into the denoise controller. The denoise controller in turn returns the mode to the IPA which now sets up the colour denoise processing appropriately. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/raspberrypi.cpp | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 8af3d603a3ff..91041fa68930 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -43,6 +43,7 @@ #include "contrast_algorithm.hpp" #include "contrast_status.h" #include "controller.hpp" +#include "denoise_algorithm.hpp" #include "dpc_status.h" #include "focus_status.h" #include "geq_status.h" @@ -553,7 +554,8 @@ bool IPARPi::validateIspControls() V4L2_CID_USER_BCM2835_ISP_DENOISE, V4L2_CID_USER_BCM2835_ISP_SHARPEN, V4L2_CID_USER_BCM2835_ISP_DPC, - V4L2_CID_USER_BCM2835_ISP_LENS_SHADING + V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, + V4L2_CID_USER_BCM2835_ISP_CDN, }; for (auto c : ctrls) { @@ -603,6 +605,14 @@ static const std::map AwbModeTable = { { controls::AwbCustom, "custom" }, }; +static const std::map DenoiseModeTable = { + { controls::draft::NoiseReductionModeOff, RPiController::DenoiseMode::Off }, + { controls::draft::NoiseReductionModeFast, RPiController::DenoiseMode::Fast }, + { controls::draft::NoiseReductionModeHighQuality, RPiController::DenoiseMode::HighQuality }, + { controls::draft::NoiseReductionModeMinimal, RPiController::DenoiseMode::Fast }, + { controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::HighQuality }, +}; + void IPARPi::queueRequest(const ControlList &controls) { /* Clear the return metadata buffer. */ @@ -806,6 +816,22 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::NOISE_REDUCTION_MODE: { + RPiController::DenoiseAlgorithm *sdn = dynamic_cast( + controller_.GetAlgorithm("SDN")); + ASSERT(sdn); + + int32_t idx = ctrl.second.get(); + if (DenoiseModeTable.count(idx)) { + sdn->SetMode(DenoiseModeTable.at(idx)); + libcameraMetadata_.set(controls::draft::NoiseReductionMode, idx); + } else { + LOG(IPARPI, Error) << "Noise reduction mode " << idx + << " not recognised"; + } + break; + } + default: LOG(IPARPI, Warning) << "Ctrl " << controls::controls.at(ctrl.first)->name() @@ -1052,9 +1078,28 @@ void IPARPi::applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ct denoise.strength.num = 1000 * denoiseStatus->strength; denoise.strength.den = 1000; + /* Set the CDN mode to match the SDN operating mode. */ + bcm2835_isp_cdn cdn; + switch (denoiseStatus->mode) { + case RPiController::DenoiseMode::Fast: + cdn.enabled = 1; + cdn.mode = CDN_MODE_FAST; + break; + case RPiController::DenoiseMode::HighQuality: + cdn.enabled = 1; + cdn.mode = CDN_MODE_HIGH_QUALITY; + break; + default: + cdn.enabled = 0; + } + ControlValue c(Span{ reinterpret_cast(&denoise), sizeof(denoise) }); ctrls.set(V4L2_CID_USER_BCM2835_ISP_DENOISE, c); + + c = ControlValue(Span{ reinterpret_cast(&cdn), + sizeof(cdn) }); + ctrls.set(V4L2_CID_USER_BCM2835_ISP_CDN, c); } void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls)