From patchwork Wed Jul 22 13:30:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 8921 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 D2951BDB1B for ; Wed, 22 Jul 2020 13:30:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C0FE60991; Wed, 22 Jul 2020 15:30:33 +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="v5RGy43m"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9257260540 for ; Wed, 22 Jul 2020 15:30:32 +0200 (CEST) Received: by mail-pf1-x442.google.com with SMTP id a14so1298822pfi.2 for ; Wed, 22 Jul 2020 06:30:32 -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=K57dU5fR3o0ZZW/FaxLXeft1XT7kjvlbON2oY1sl2kk=; b=v5RGy43m4TNVUy1PHjWkwp42aOAXKjc9UwKTk81xhEey2XU0fOR3J/hSXZtkZpD64Z KJKqFpARMPY/g7paceCDnYYtL+IIJwgsknkqEFtndhM/6OudWToEqVO3c9BnlVDKf5JY td71E9b6+j23rWN/DV2GywCA9gTzs5bby8LFqb10mQpqwsjztQS7Tw2UF6aEsvSDHh46 lC1WxGTcVsyf8W6GxSHBli37hlsnEmTgnaOIfDQ2jZn65ErnzHb5vZNWYAhpXLwPbJpV OSuGY1tKrIOn/58T/Kl8DRhZZrnbeQ5+j39Na5gnmi/ImcqB5Go/UNlOjdqMrNUxWz9I NNGA== 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=K57dU5fR3o0ZZW/FaxLXeft1XT7kjvlbON2oY1sl2kk=; b=Y+yDU0SmGuZ4EzI1rRc6Hi+RVT+0UcaxAFkW7d0S+EVbib/Kb68OlJLCqnEI60sUvt jLzrVcueYyzTHCEeLU0Vjhat1k3rPOyoTEHep970edtsTdkfUSODv5Zs2oj6VhYnEDGJ 1iW50Zzge6mX2nKVkaz6FSDXiScJgha1bkQqLFWd0bo3rGYCY6Z1KHbokRlNhD7FPwOH baG1EKPm/NN407KUjQ2aFk4vlShw2KTbK1yKSXwzKmtlKCGLc6cQdJv7n+FIRY26qRSL OIGdVyJwkhQzjhnn9fi7/RPlF28Fv+QCaXRWN5E76T8R2QqUosa/ln7+WgnzPou+NDtx UdXA== X-Gm-Message-State: AOAM5313rMlfHLZQAJtbnUmzWWWRZeptViQ62L4Pjrq9iQXcL3Kr9Hoi qX08eE4tnHk6wY6b6q3E6LZDbURtBwA= X-Google-Smtp-Source: ABdhPJwFc7TOj7Fz78taJsBoyNhO/ep1FTUFYdECs3pio5mV5r80pmq2PoKkPVe2bjiffh6jkuZC2w== X-Received: by 2002:aa7:8f03:: with SMTP id x3mr27392325pfr.64.1595424631094; Wed, 22 Jul 2020 06:30:31 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.178]) by smtp.gmail.com with ESMTPSA id z2sm24295928pff.36.2020.07.22.06.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 06:30:30 -0700 (PDT) From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham Date: Wed, 22 Jul 2020 19:00:06 +0530 Message-Id: <20200722133009.26528-5-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 4/7] libcamera: pipeline: vimc: Configure the entities of VIMC pipeline 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" Configure the pads according to the configuration asked for. In case only one stream (RBG or RAW) is asked for, configurations still need to be set on the other entities in the pipeline. Signed-off-by: Kaaira Gupta --- src/libcamera/pipeline/vimc/vimc.cpp | 175 ++++++++++++++++++--------- 1 file changed, 121 insertions(+), 54 deletions(-) diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 83dd541..c2ed5b6 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -295,68 +295,135 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera, int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config) { VimcCameraData *data = cameraData(camera); - StreamConfiguration &cfg = config->at(0); - int ret; + for (unsigned i = 0; i < config->size(); i++) { + StreamConfiguration &cfg = config->at(i); + const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); + int ret; + if (info.isRaw(cfg.pixelFormat)) { + V4L2SubdeviceFormat subformat = {}; + subformat.mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8; + subformat.size = cfg.size; + ret = data->sensor_->setFormat(&subformat); + if (ret) + return ret; + + V4L2DeviceFormat format = {}; + format.fourcc = data->raw_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + ret = data->raw_->setFormat(&format); + if (ret) + return ret; + + /* + * Formats have to be set on debayer, scaler, and RGB/YUB Capture + * otherwise the VIMC driver will fail pipeline validation + */ + + ret = data->debayer_->setFormat(0, &subformat); + if (ret) + return ret; + + subformat.mbus_code = MEDIA_BUS_FMT_RGB888_1X24; + ret = data->debayer_->setFormat(1, &subformat); + if (ret) + return ret; + + ret = data->scaler_->setFormat(0, &subformat); + if (ret) + return ret; + + if (data->media_->version() >= KERNEL_VERSION(5, 6, 0)) { + Rectangle crop = { + .x = 0, + .y = 0, + .width = subformat.size.width, + .height = subformat.size.height, + }; + ret = data->scaler_->setSelection(0, V4L2_SEL_TGT_CROP, &crop); + if (ret) + return ret; + } - /* The scaler hardcodes a x3 scale-up ratio. */ - V4L2SubdeviceFormat subformat = {}; - subformat.mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8; - subformat.size = { cfg.size.width / 3, cfg.size.height / 3 }; + subformat.mbus_code = MEDIA_BUS_FMT_RGB888_1X24; + subformat.size = { cfg.size.width * 3, cfg.size.height * 3 }; + ret = data->scaler_->setFormat(1, &subformat); + if (ret) + return ret; - ret = data->sensor_->setFormat(&subformat); - if (ret) - return ret; + format.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_RGB24); + format.size = { cfg.size.width * 3, cfg.size.height * 3 }; + ret = data->video_->setFormat(&format); + if (ret) + return ret; - ret = data->debayer_->setFormat(0, &subformat); - if (ret) - return ret; + cfg.setStream(&data->rawStream_); - subformat.mbus_code = pixelformats.find(cfg.pixelFormat)->second; - ret = data->debayer_->setFormat(1, &subformat); - if (ret) - return ret; + } else { + /* The scaler hardcodes a x3 scale-up ratio. */ + V4L2SubdeviceFormat subformat = {}; + subformat.mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8; + subformat.size = { cfg.size.width / 3, cfg.size.height / 3 }; + + ret = data->sensor_->setFormat(&subformat); + if (ret) + return ret; + + ret = data->debayer_->setFormat(0, &subformat); + if (ret) + return ret; + + subformat.mbus_code = pixelformats.find(cfg.pixelFormat)->second; + ret = data->debayer_->setFormat(1, &subformat); + if (ret) + return ret; + + ret = data->scaler_->setFormat(0, &subformat); + if (ret) + return ret; + + if (data->media_->version() >= KERNEL_VERSION(5, 6, 0)) { + Rectangle crop = { + .x = 0, + .y = 0, + .width = subformat.size.width, + .height = subformat.size.height, + }; + ret = data->scaler_->setSelection(0, V4L2_SEL_TGT_CROP, &crop); + if (ret) + return ret; + } - ret = data->scaler_->setFormat(0, &subformat); - if (ret) - return ret; + subformat.size = cfg.size; + ret = data->scaler_->setFormat(1, &subformat); + if (ret) + return ret; - if (data->media_->version() >= KERNEL_VERSION(5, 6, 0)) { - Rectangle crop{ 0, 0, subformat.size }; - ret = data->scaler_->setSelection(0, V4L2_SEL_TGT_CROP, &crop); - if (ret) - return ret; + V4L2DeviceFormat format = {}; + format.fourcc = data->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + ret = data->video_->setFormat(&format); + if (ret) + return ret; + + if (format.size != cfg.size || + format.fourcc != data->video_->toV4L2PixelFormat(cfg.pixelFormat)) + return -EINVAL; + + /* + * Format has to be set on the raw capture video node, otherwise the + * vimc driver will fail pipeline validation. + */ + format.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8); + format.size = { cfg.size.width / 3, cfg.size.height / 3 }; + + ret = data->raw_->setFormat(&format); + if (ret) + return ret; + + cfg.setStream(&data->rgbStream_); + } } - subformat.size = cfg.size; - ret = data->scaler_->setFormat(1, &subformat); - if (ret) - return ret; - - V4L2DeviceFormat format = {}; - format.fourcc = data->video_->toV4L2PixelFormat(cfg.pixelFormat); - format.size = cfg.size; - - ret = data->video_->setFormat(&format); - if (ret) - return ret; - - if (format.size != cfg.size || - format.fourcc != data->video_->toV4L2PixelFormat(cfg.pixelFormat)) - return -EINVAL; - - /* - * Format has to be set on the raw capture video node, otherwise the - * vimc driver will fail pipeline validation. - */ - format.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8); - format.size = { cfg.size.width / 3, cfg.size.height / 3 }; - - ret = data->raw_->setFormat(&format); - if (ret) - return ret; - - cfg.setStream(&data->rgbStream_); - return 0; }