From patchwork Tue Nov 23 13:10:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14711 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 E3BE2BF415 for ; Tue, 23 Nov 2021 13:11:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9CAD66039C; Tue, 23 Nov 2021 14:11:19 +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="grSW6ikL"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E48160121 for ; Tue, 23 Nov 2021 14:11:15 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso2204757wml.1 for ; Tue, 23 Nov 2021 05:11:15 -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=c+DaaEB0OradqvdNNgMUiPLcQhdP5VfIfypiBu6Wn/A=; b=grSW6ikLFwsAOweut/65X1EBYCFbiSUyp5H4KpGwaqmxvZqKAX3yGzUAB5k25xmPrL jIFVNcvIvi5o4CVOdD7ZLZyAIABYaFzxaPLqaw4rbBd3LwBgQAlk/7A3yf9BdvqJDABA Sv32ayjVsdFIkEBDg8eMfhBOJ3186j2KiDZj/6Whb5bvOfY19DuBkE+p1r5VFI2VRaAi gAosBk4YWz0gek2plNNGzxQMB2NA+EytPQw41egHa2IzwTdRxhRwoyj0hgrqihnSr5J/ LcwaEAimBVkcVx010MMzhcV4aTnW8ySZ5wYuCb4tyis7a0gQsXA4euqi63M3I1cq5Weh /6sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c+DaaEB0OradqvdNNgMUiPLcQhdP5VfIfypiBu6Wn/A=; b=njsd+LnUouT3USJ/UwGF7Gmjj7/MVSxH46Av4SLlnMYJPlGG+AZpC4UyY5yc6VGoMO rridHz75bguJoXKanLnwFBxFPmPMIq+g3wHtuLaAWcXx6XmWXGUE4kU0ykKN9MjKyRYB DdtkITKt2Irc/Jjgz5m+uQtdetqNOpNI4SSYU0i8yQGFjCakIjzC/ajPc+l4wss8UTmW rGSq9SA+hWAqyL31xP26u4G+2+xdhe9dOxStw3jc50aYD+4QHAguVGn1sC0PSLg1OQkj v0h+cbBXwXKVqKJpNnvFORPkmgtMJmZFLrbth3IhOUNKJtAPo39QPApudOFWLYyxqLR6 Y2wA== X-Gm-Message-State: AOAM533sTPE1orf/bgQ44BU8AQqhYCJ9KaLNRjNUGWu/PI+H7Ymie5SB Thl8ZGPUiCvErOcbN03sQ9YQ8mapuhxLFl30 X-Google-Smtp-Source: ABdhPJwbOlhPp2+a5glelRtvUWCEgudQ3cAJAhGIh/qx0r/YHacKcFC1/QiaQBh1DuRN/rrtCdppVw== X-Received: by 2002:a1c:8002:: with SMTP id b2mr3093672wmd.2.1637673074891; Tue, 23 Nov 2021 05:11:14 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:34c6:a31e:c2e1:260d]) by smtp.gmail.com with ESMTPSA id b197sm1106142wmb.24.2021.11.23.05.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 05:11:13 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 13:10:39 +0000 Message-Id: <20211123131040.1542581-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123131040.1542581-1-naush@raspberrypi.com> References: <20211123131040.1542581-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/2] pipeline: raspberrypi: Split out device enumeration and camera registration 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" Split out PipelineHandlerRPi::match() so that media device enumeration and acquisition is separated from camera registration. The former logic remains in PipelineHandlerRPi::match(), whereas the latter logic is moved into a new PipelineHandlerRPi::registerCamera() member function. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 4f6c699a4379..12fd38061241 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -311,6 +311,7 @@ private: return static_cast(camera->_d()); } + bool registerCamera(); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); @@ -1010,6 +1011,11 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) if (!isp_) return false; + return registerCamera(); +} + +bool PipelineHandlerRPi::registerCamera() +{ std::unique_ptr data = std::make_unique(this); if (!data->dmaHeap_.isValid()) return false; @@ -1170,7 +1176,7 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) const std::string &id = data->sensor_->id(); std::shared_ptr camera = Camera::create(std::move(data), id, streams); - registerCamera(std::move(camera)); + PipelineHandler::registerCamera(std::move(camera)); return true; } From patchwork Tue Nov 23 13:10:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14712 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 2AB07C324F for ; Tue, 23 Nov 2021 13:11:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 373D1603C2; Tue, 23 Nov 2021 14:11:20 +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="QkUycv9P"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9792E60230 for ; Tue, 23 Nov 2021 14:11:16 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id s13so38937879wrb.3 for ; Tue, 23 Nov 2021 05:11:16 -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=ggF4Mfm9Kuz2SdxEbLUoqjJl/yr8IZtfRCVoHgVM3To=; b=QkUycv9PkprUJNoP4kCl1nyAWcZpUfxZW4So8pE5a6ZoY+o36rlqN4rp1YRXavBItc ihg6hF2J3tDW6jhzaWEhayB3ykhGerSV2e8Mj3OPTkF8It7OMNZ1PXiSrL2iFMLJKZcl AIR/IiCdAvev9AFSEEfyjwbGpHfe9CQ58KTZb4/117ZX0QPUbHSpPGH0tt2l+U8P/BE7 SzGiOrKKiqtN8dLlpAjVNkddpcsvghkZ8jT/vML6NIUHL2VQ64fhbAeCTxqIYIwdLitK a1I+VSNoghMtBPt08LqM6kLg4pMmFc7aNRHcMmy4ip11T275LKeP4v//pd0ujWCWjK+V /18A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ggF4Mfm9Kuz2SdxEbLUoqjJl/yr8IZtfRCVoHgVM3To=; b=bqckVjaNCTLiILxDDJrAMZzfP4PxZSJdWUKBGMc18tA7DiUHfMMD0tTcpaxFNntO6A qN+1W7CdM41w9XAjOIC8a2UfYgOgbe5mrDOWGE+VrVwEPuVtoDMQP9eTA41L9D4b9GvL Rjc+vG/Ay/lvydm7dbHtomEm39HuW9GQDi4cO5nU892WY//hrFszDTK371TViKjlXw22 KqcqWuvA5ghLsZ7Hp8TcjtSxpXwQun1dCjBDSCrLmNatnTvTQD6j1qW6/ChB0LVUr2bJ RPX7yOFOCZUX9yx6kZl5P6WVCTkyd1MpcIEA+cAb0aoQxrJc1Uvz+mkrt251vue3MezG G+nQ== X-Gm-Message-State: AOAM533oQjkQ6XDYDDWjFRduwVDD8s1SkszONahrptv3d0ZPv79F9pRC SbHCSSpFCY31ZO06Qf9uQ/DXHOCOR7cJ0qnE X-Google-Smtp-Source: ABdhPJxfzbPvjkAR7GBRnvHB7ibDTwRMUWLsYJOjif0YNMaNe50b6B98VMkSgozarMwZs1sfz+7Vwg== X-Received: by 2002:a05:6000:1acd:: with SMTP id i13mr7330504wry.398.1637673076038; Tue, 23 Nov 2021 05:11:16 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:34c6:a31e:c2e1:260d]) by smtp.gmail.com with ESMTPSA id b197sm1106142wmb.24.2021.11.23.05.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 05:11:15 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 13:10:40 +0000 Message-Id: <20211123131040.1542581-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123131040.1542581-1-naush@raspberrypi.com> References: <20211123131040.1542581-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/2] pipeline: raspberrypi: Tidy the camera enumeration and registration logic 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" When acquiring the media device, it is not necessary to match all entity names, so remove it. Aditionally, we do not need to keep the MediaEntity pointers for the Unicam and ISP devices stored within the PipelineHandlerRPi class. Instead these can be stored locally in PipelineHandlerRPi::match(). PipelineHandlerRPi::registerCamera() now returns an int error code instead of a boolean for pass/fail. Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 88 +++++++++++-------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 12fd38061241..c5034480820e 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -311,14 +311,11 @@ private: return static_cast(camera->_d()); } - bool registerCamera(); + int registerCamera(MediaDevice *unicam, MediaDevice *isp); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); void mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask); - - MediaDevice *unicam_; - MediaDevice *isp_; }; RPiCameraConfiguration::RPiCameraConfiguration(const RPiCameraData *data) @@ -509,7 +506,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } PipelineHandlerRPi::PipelineHandlerRPi(CameraManager *manager) - : PipelineHandler(manager), unicam_(nullptr), isp_(nullptr) + : PipelineHandler(manager) { } @@ -993,49 +990,65 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) { + MediaDevice *unicamDevice, *ispDevice; + DeviceMatch unicam("unicam"); - DeviceMatch isp("bcm2835-isp"); + unicamDevice = acquireMediaDevice(enumerator, unicam); - unicam.add("unicam-image"); + if (!unicamDevice) { + LOG(RPI, Debug) << "Unable to acquire a Unicam instance"; + return false; + } - isp.add("bcm2835-isp0-output0"); /* Input */ - isp.add("bcm2835-isp0-capture1"); /* Output 0 */ - isp.add("bcm2835-isp0-capture2"); /* Output 1 */ - isp.add("bcm2835-isp0-capture3"); /* Stats */ + DeviceMatch isp("bcm2835-isp"); + ispDevice = acquireMediaDevice(enumerator, isp); - unicam_ = acquireMediaDevice(enumerator, unicam); - if (!unicam_) + if (!ispDevice) { + LOG(RPI, Debug) << "Unable to acquire ISP instance"; return false; + } - isp_ = acquireMediaDevice(enumerator, isp); - if (!isp_) + int ret = registerCamera(unicamDevice, ispDevice); + if (ret) { + LOG(RPI, Error) << "Failed to register camera: " << ret; return false; + } - return registerCamera(); + return true; } -bool PipelineHandlerRPi::registerCamera() +int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp) { std::unique_ptr data = std::make_unique(this); + if (!data->dmaHeap_.isValid()) - return false; + return -ENOMEM; + + MediaEntity *unicamImage = unicam->getEntityByName("unicam-image"); + MediaEntity *ispOutput0 = isp->getEntityByName("bcm2835-isp0-output0"); + MediaEntity *ispCapture1 = isp->getEntityByName("bcm2835-isp0-capture1"); + MediaEntity *ispCapture2 = isp->getEntityByName("bcm2835-isp0-capture2"); + MediaEntity *ispCapture3 = isp->getEntityByName("bcm2835-isp0-capture3"); + + if (!unicamImage || !ispOutput0 || !ispCapture1 || !ispCapture2 || !ispCapture3) + return -ENOENT; /* Locate and open the unicam video streams. */ - data->unicam_[Unicam::Image] = RPi::Stream("Unicam Image", unicam_->getEntityByName("unicam-image")); + data->unicam_[Unicam::Image] = RPi::Stream("Unicam Image", unicamImage); /* An embedded data node will not be present if the sensor does not support it. */ - MediaEntity *embeddedEntity = unicam_->getEntityByName("unicam-embedded"); - if (embeddedEntity) { - data->unicam_[Unicam::Embedded] = RPi::Stream("Unicam Embedded", embeddedEntity); + MediaEntity *unicamEmbedded = unicam->getEntityByName("unicam-embedded"); + if (unicamEmbedded) { + data->unicam_[Unicam::Embedded] = RPi::Stream("Unicam Embedded", unicamEmbedded); data->unicam_[Unicam::Embedded].dev()->bufferReady.connect(data.get(), &RPiCameraData::unicamBufferDequeue); } /* Tag the ISP input stream as an import stream. */ - data->isp_[Isp::Input] = RPi::Stream("ISP Input", isp_->getEntityByName("bcm2835-isp0-output0"), true); - data->isp_[Isp::Output0] = RPi::Stream("ISP Output0", isp_->getEntityByName("bcm2835-isp0-capture1")); - data->isp_[Isp::Output1] = RPi::Stream("ISP Output1", isp_->getEntityByName("bcm2835-isp0-capture2")); - data->isp_[Isp::Stats] = RPi::Stream("ISP Stats", isp_->getEntityByName("bcm2835-isp0-capture3")); + data->isp_[Isp::Input] = RPi::Stream("ISP Input", ispOutput0, true); + data->isp_[Isp::Output0] = RPi::Stream("ISP Output0", ispCapture1); + data->isp_[Isp::Output1] = RPi::Stream("ISP Output1", ispCapture2); + data->isp_[Isp::Stats] = RPi::Stream("ISP Stats", ispCapture3); /* Wire up all the buffer connections. */ data->unicam_[Unicam::Image].dev()->frameStart.connect(data.get(), &RPiCameraData::frameStarted); @@ -1046,7 +1059,7 @@ bool PipelineHandlerRPi::registerCamera() data->isp_[Isp::Stats].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue); /* Identify the sensor. */ - for (MediaEntity *entity : unicam_->entities()) { + for (MediaEntity *entity : unicam->entities()) { if (entity->function() == MEDIA_ENT_F_CAM_SENSOR) { data->sensor_ = std::make_unique(entity); break; @@ -1054,23 +1067,23 @@ bool PipelineHandlerRPi::registerCamera() } if (!data->sensor_) - return false; + return -EINVAL; if (data->sensor_->init()) - return false; + return -EINVAL; data->sensorFormats_ = populateSensorFormats(data->sensor_); ipa::RPi::SensorConfig sensorConfig; if (data->loadIPA(&sensorConfig)) { LOG(RPI, Error) << "Failed to load a suitable IPA library"; - return false; + return -EINVAL; } - if (sensorConfig.sensorMetadata ^ !!embeddedEntity) { + if (sensorConfig.sensorMetadata ^ !!unicamEmbedded) { LOG(RPI, Warning) << "Mismatch between Unicam and CamHelper for embedded data usage!"; sensorConfig.sensorMetadata = false; - if (embeddedEntity) + if (unicamEmbedded) data->unicam_[Unicam::Embedded].dev()->bufferReady.disconnect(); } @@ -1091,12 +1104,12 @@ bool PipelineHandlerRPi::registerCamera() for (auto stream : data->streams_) { if (stream->dev()->open()) - return false; + continue; } if (!data->unicam_[Unicam::Image].dev()->caps().hasMediaController()) { LOG(RPI, Error) << "Unicam driver does not use the MediaController, please update your kernel!"; - return false; + return -EINVAL; } /* @@ -1158,7 +1171,7 @@ bool PipelineHandlerRPi::registerCamera() if (!bayerFormat.isValid()) { LOG(RPI, Error) << "No Bayer format found"; - return false; + return -EINVAL; } data->nativeBayerOrder_ = bayerFormat.order; @@ -1178,7 +1191,10 @@ bool PipelineHandlerRPi::registerCamera() Camera::create(std::move(data), id, streams); PipelineHandler::registerCamera(std::move(camera)); - return true; + LOG(RPI, Info) << "Registered camera " << id + << " to Unicam device " << unicam->deviceNode() + << " and ISP device " << isp->deviceNode(); + return 0; } int PipelineHandlerRPi::queueAllBuffers(Camera *camera)