From patchwork Wed Jul 22 13:30:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 8920 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 63061BDB1B for ; Wed, 22 Jul 2020 13:30:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B81B609C5; Wed, 22 Jul 2020 15:30:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="1FyqB4Kf"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EB1960540 for ; Wed, 22 Jul 2020 15:30:29 +0200 (CEST) Received: by mail-pl1-x636.google.com with SMTP id w17so987799ply.11 for ; Wed, 22 Jul 2020 06:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KSv3HNYWyvKZjLaLjbxU0Va1M99Ttw6+yOqTeHiqQqo=; b=1FyqB4KfD+VMyvTbYFuYpK2+MrsgenBgtBYa4rATVdo9F7zoEWcBuDIs66/uvtJhYY 6iwZnoe6P/CgsP4t44t8RgPipFY+ASk04PuDIVPuTr4nNnSTpzOXQSZq1uQXnLy4xejN FUkBD+yInOIhitkrg4tq2biMwqdfGadMH6WhMz0/EPtxRlvo8+VDgBq1xbz/7o9/+8YL cap34UVvfA5h2WKfv953nVWciaRBq3tuzGYAromrZ2IU4C1anISgavneUzsF/km62ltm KY28iT6/QNv92cTrglf4TW0HIB3Q4u4rHrTjQKFyXKQ7/A3zPin7L5m8mq6+QIOYWyyc 6jUg== 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; bh=KSv3HNYWyvKZjLaLjbxU0Va1M99Ttw6+yOqTeHiqQqo=; b=BdUeUVMpuSsp78envmQucfdABp+ogNJIOfpB7qlPAuyrtqiTcHtnXXuSlOUDee9QC7 u/x/YqoqOizTsO7ilVERToNIMiB9Vr01vHtCuQ+eC2Uv2IyeXLUinO4n5shytAkqKFro 2q+ROw1iU7wGLpGLClbsGOqIti8NjqlvETLQdXwN+nq8U1QSXJbyP//LR769cUe7mIDT qHVK1GiH5SpnJOve/zFzALEhUYMuR2Tc/m0/SiSooQdfZXX3TfSkfa0k/GZUoZmNB+YW WRqrL3HpkzhDtkYLRX7ip6OwyEwJ3fhTC/TGZnlXsxvslKv3uDEoFVbMMTZNMES5s9ka myOQ== X-Gm-Message-State: AOAM533Bd6pKHT3ANxDOGifZb0koK2qj8Lu2xEyTY4znSrTxZyCJixQR zAAgexBX5huTQo/MlrIP6qRgvw== X-Google-Smtp-Source: ABdhPJwDrLd74zaSCY7s1Ud818sW9nlNgq1A31DmqYA3nYEZQ8WmAsBKsKlK57cj9/+k2GuSJ2tLqA== X-Received: by 2002:a17:90a:d998:: with SMTP id d24mr9718553pjv.43.1595424627318; Wed, 22 Jul 2020 06:30:27 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.178]) by smtp.gmail.com with ESMTPSA id n14sm21791703pgd.78.2020.07.22.06.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 06:30:26 -0700 (PDT) From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham Date: Wed, 22 Jul 2020 19:00:05 +0530 Message-Id: <20200722133009.26528-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722133009.26528-1-kgupta@es.iitr.ac.in> References: <20200722133009.26528-1-kgupta@es.iitr.ac.in> Subject: [libcamera-devel] [PATCH 3/7] libcamera: pipeline: vimc: Generate and Validate stream configurations 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: Kaaira Gupta MIME-Version: 1.0 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement generating configurations for StillCaptureRaw role. Also validate them. Declare a bool which takes note of the configuration which is raw (if any). If two configurations are asked for, we consider one of them to be asking for a raw stream. If no role is provided, consider the configuration with least with to be associated wth raw stream. If both the pixelformat and size are provided, give preferance to pixelformat in determining the configuration with raw stream. Signed-off-by: Kaaira Gupta --- src/libcamera/pipeline/vimc/vimc.cpp | 180 ++++++++++++++++++--------- 1 file changed, 122 insertions(+), 58 deletions(-) diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index bd6ddde..83dd541 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -117,6 +117,17 @@ static const std::map pixelformats{ { formats::BGR888, MEDIA_BUS_FMT_RGB888_1X24 }, }; +static const std::map pixelFormatsRaw{ + { formats::SBGGR8, MEDIA_BUS_FMT_SBGGR8_1X8 }, + { formats::SGBRG8, MEDIA_BUS_FMT_SGBRG8_1X8 }, + { formats::SGRBG8, MEDIA_BUS_FMT_SGRBG8_1X8 }, + { formats::SRGGB8, MEDIA_BUS_FMT_SRGGB8_1X8 }, + { formats::SBGGR10, MEDIA_BUS_FMT_SBGGR10_1X10 }, + { formats::SGBRG10, MEDIA_BUS_FMT_SGBRG10_1X10 }, + { formats::SGRBG10, MEDIA_BUS_FMT_SGRBG10_1X10 }, + { formats::SRGGB10, MEDIA_BUS_FMT_SRGGB10_1X10 } +}; + } /* namespace */ VimcCameraConfiguration::VimcCameraConfiguration(VimcCameraData *data) @@ -127,53 +138,90 @@ VimcCameraConfiguration::VimcCameraConfiguration(VimcCameraData *data) CameraConfiguration::Status VimcCameraConfiguration::validate() { Status status = Valid; + bool hasRaw = false; + unsigned rindex = 2; + int ret; if (config_.empty()) return Invalid; /* Cap the number of entries to the available streams. */ - if (config_.size() > 1) { - config_.resize(1); + if (config_.size() > 2) { + config_.resize(2); status = Adjusted; } - StreamConfiguration &cfg = config_[0]; - - /* Adjust the pixel format. */ - const std::vector formats = cfg.formats().pixelformats(); - if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) == formats.end()) { - LOG(VIMC, Debug) << "Adjusting format to BGR888"; - cfg.pixelFormat = formats::BGR888; - status = Adjusted; + if (config_.size() > 1) { + if (config_[0].size.width < config_[1].size.width) { + rindex = 0; + } else { + rindex = 1; + } + hasRaw = true; } - /* Clamp the size based on the device limits. */ - const Size size = cfg.size; - - /* The scaler hardcodes a x3 scale-up ratio. */ - cfg.size.width = std::max(48U, std::min(4096U, cfg.size.width)); - cfg.size.height = std::max(48U, std::min(2160U, cfg.size.height)); - cfg.size.width -= cfg.size.width % 3; - cfg.size.height -= cfg.size.height % 3; - - if (cfg.size != size) { - LOG(VIMC, Debug) - << "Adjusting size to " << cfg.size.toString(); - status = Adjusted; + for (unsigned i = 0; i < config_.size(); i++) { + const PixelFormatInfo &info = PixelFormatInfo::info(config_[i].pixelFormat); + if (info.isRaw(config_[i].pixelFormat)) { + rindex = i; + hasRaw = true; + } } - cfg.bufferCount = 4; + for (unsigned i = 0; i < config_.size(); i++) { + StreamConfiguration &cfg = config_[i]; + V4L2DeviceFormat format = {}; + const Size size = cfg.size; + if (i == rindex) { + /* Clamp the size based on the device limits. */ + cfg.size.width = std::max(16U, std::min(1365U, cfg.size.width)); + cfg.size.height = std::max(16U, std::min(720U, cfg.size.height)); + /* Adjust the pixel format. */ + if (pixelFormatsRaw.find(cfg.pixelFormat) == pixelFormatsRaw.end()) { + LOG(VIMC, Debug) << "Adjusting format to SGRBG8"; + cfg.pixelFormat = formats::SGRBG8; + status = Adjusted; + } + format.fourcc = data_->raw_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + ret = data_->raw_->tryFormat(&format); + } else { + const std::vector formats = cfg.formats().pixelformats(); + if (hasRaw) { + cfg.size.width = config_[(i + 1) % 2].size.width * 3; + cfg.size.height = config_[(i + 1) % 2].size.height * 3; + } else { + /* Clamp the size based on the device limits. */ + cfg.size.width = std::max(48U, std::min(4096U, cfg.size.width)); + cfg.size.height = std::max(48U, std::min(2160U, cfg.size.height)); + /* The scaler hardcodes a x3 scale-up ratio. */ + cfg.size.width -= cfg.size.width % 3; + cfg.size.height -= cfg.size.height % 3; + } - V4L2DeviceFormat format = {}; - format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); - format.size = cfg.size; + /* Adjust the pixel format. */ + if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) == formats.end()) { + LOG(VIMC, Debug) << "Adjusting format to BGR888"; + cfg.pixelFormat = formats::BGR888; + status = Adjusted; + } + format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + ret = data_->video_->tryFormat(&format); + } - int ret = data_->video_->tryFormat(&format); - if (ret) - return Invalid; + if (ret) + return Invalid; + if (cfg.size != size) { + LOG(VIMC, Debug) + << "Adjusting size to " << cfg.size.toString(); + status = Adjusted; + } - cfg.stride = format.planes[0].bpl; - cfg.frameSize = format.planes[0].size; + cfg.bufferCount = 4; + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + } return status; } @@ -194,35 +242,51 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera, std::map> formats; - for (const auto &pixelformat : pixelformats) { - /* - * Kernels prior to v5.7 incorrectly report support for RGB888, - * but it isn't functional within the pipeline. - */ - if (data->media_->version() < KERNEL_VERSION(5, 7, 0)) { - if (pixelformat.first != formats::BGR888) { - LOG(VIMC, Info) - << "Skipping unsupported pixel format " - << pixelformat.first.toString(); - continue; + for (const StreamRole role : roles) { + switch (role) { + case StreamRole::StillCaptureRaw: { + for (const auto &pixelformat : pixelFormatsRaw) { + std::vector sizes{ + SizeRange{ { 16, 16 }, { 1365, 720 } } + }; + formats[pixelformat.first] = sizes; + } + StreamConfiguration cfg(formats); + cfg.pixelFormat = formats::SGRBG8; + cfg.size = { 640, 360 }; + cfg.bufferCount = 4; + config->addConfiguration(cfg); + break; + } + default: + for (const auto &pixelformat : pixelformats) { + /* + * Kernels prior to v5.7 incorrectly report support for RGB888, + * but it isn't functional within the pipeline. + */ + if (data->media_->version() < KERNEL_VERSION(5, 7, 0)) { + if (pixelformat.first != formats::BGR888) { + LOG(VIMC, Info) + << "Skipping unsupported pixel format " + << pixelformat.first.toString(); + continue; + } + } + + /* The scaler hardcodes a x3 scale-up ratio. */ + std::vector sizes{ + SizeRange{ { 48, 48 }, { 4096, 2160 } } + }; + formats[pixelformat.first] = sizes; } + StreamConfiguration cfg(formats); + cfg.pixelFormat = formats::BGR888; + cfg.size = { 1920, 1080 }; + cfg.bufferCount = 4; + config->addConfiguration(cfg); + break; } - - /* The scaler hardcodes a x3 scale-up ratio. */ - std::vector sizes{ - SizeRange{ { 48, 48 }, { 4096, 2160 } } - }; - formats[pixelformat.first] = sizes; } - - StreamConfiguration cfg(formats); - - cfg.pixelFormat = formats::BGR888; - cfg.size = { 1920, 1080 }; - cfg.bufferCount = 4; - - config->addConfiguration(cfg); - config->validate(); return config;