From patchwork Wed Dec 1 11:57:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14957 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 BE590C3250 for ; Wed, 1 Dec 2021 11:57:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5B5EB6059C; Wed, 1 Dec 2021 12:57:24 +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="N2EhLhdM"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B3A46011A for ; Wed, 1 Dec 2021 12:57:23 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id t9so34685231wrx.7 for ; Wed, 01 Dec 2021 03:57:23 -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=49BdeSGrYkKnPrwypx/xXitVPSiEQrgJRyauOS4rVKk=; b=N2EhLhdM4V/UCs7rKPwLdbGOsIOIGRC9NzE2y6adyYSWSmJRCGTR3C17kySEB0cbQI xl/kavMlG757YjOBr3lFywwhaGKY1lgzhlMfT9ndLu4cCo1oRBq6J3785q2A9uUNwbwb J2nAQkKVmoBqhyfPC4PQSL5i1sEssTZRgZU/XOSnARJ/RFC1FvvELt06iPODzrKYY5kP gHLEnt1GP8iYk8S+6f4h72ZIuu6fYFa35/B3bjOt1i6vmToVMvjWA3qnDCevF4ZH0skV NkWOiPfl6ynyKKapXQs5uexX4Uh/697fQNYPKZBOrgezGAnkF9Q27G/kpn5sSVTnJR26 CDzg== 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=49BdeSGrYkKnPrwypx/xXitVPSiEQrgJRyauOS4rVKk=; b=d1LiSOBw8uzNipg+KOK/xN3tV3PMG5tAnhcIOi9SSGmUHXY3NPIFSAXKiZtK61SQ3R r5kiA2SGVCrXY+oEfA29pweJPx/g83UVwVY6Y+xEyOLBIWmr26wyCZZF4sboSjMnWs83 cx9UxY19NjtC+Eetptz+yXwDVL4zpqcdfAtG+hV8tz3gf1SFyX6jk6GZAOt5nYXsrLl1 G9s3Cq2zRRDSobfC86frKm5nkds2q0QwxTvpcRp3GwoNVfuNeCOj44IVUpKupOVlR3HN 0zYVT6ESF7Mhez3esOJAToZ6DElzN96O7Ij7uO6w15NmciQKLZRCgpyqCeT1iawEwzlW myBA== X-Gm-Message-State: AOAM531YbKUoJ/2b7TVgaH/ErpO0qDSM8kx75Sd7zVGMTPs3TUMrntBu /2HZST+14v2D4SSMD7qe4uY+5XWZ1F5VG8x1 X-Google-Smtp-Source: ABdhPJz3IYmo9Vo01X35Sipk10+KNhL3FlRvO/nYO1i/CwMgOCs8hIpLMK8Xxg8mXxau30tb2noIDA== X-Received: by 2002:a5d:4a0a:: with SMTP id m10mr5962292wrq.221.1638359842544; Wed, 01 Dec 2021 03:57:22 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9907:13eb:bd49:5862]) by smtp.gmail.com with ESMTPSA id f13sm1139451wmq.29.2021.12.01.03.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Dec 2021 03:57:22 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 11:57:10 +0000 Message-Id: <20211201115711.1017822-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211201115711.1017822-1-naush@raspberrypi.com> References: <20211201115711.1017822-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/2] pipeline: raspberrypi: Move sensor entity detection out of registerCamera() 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" Enumerate the sensor device entities in PipelineHandlerRPi::match() and loop over PipelineHandlerRPi::registerCamera() for each sensor found. This will allow the pipeline handler to register multiple cameras attached to a single Unicam instance with a Video Mux device. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- .../pipeline/raspberrypi/raspberrypi.cpp | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index e31fa3b23859..811160490f5c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -314,7 +314,7 @@ private: return static_cast(camera->_d()); } - int registerCamera(MediaDevice *unicam, MediaDevice *isp); + int registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); @@ -1009,16 +1009,28 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return false; } - int ret = registerCamera(unicamDevice, ispDevice); - if (ret) { - LOG(RPI, Error) << "Failed to register camera: " << ret; - return false; + /* + * The loop below is used to register multiple cameras behind one or more + * video mux devices that are attaced to a particular Unicam instance. + * Obviously these cameras cannot be used simultaneously. + */ + unsigned int numCameras = 0; + for (MediaEntity *entity : unicamDevice->entities()) { + if (entity->function() != MEDIA_ENT_F_CAM_SENSOR) + continue; + + int ret = registerCamera(unicamDevice, ispDevice, entity); + if (ret) + LOG(RPI, Error) << "Failed to register camera " + << entity->name() << ": " << ret; + else + numCameras++; } - return true; + return !!numCameras; } -int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp) +int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity) { std::unique_ptr data = std::make_unique(this); @@ -1059,14 +1071,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp) data->isp_[Isp::Output1].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue); data->isp_[Isp::Stats].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue); - /* Identify the sensor. */ - for (MediaEntity *entity : unicam->entities()) { - if (entity->function() == MEDIA_ENT_F_CAM_SENSOR) { - data->sensor_ = std::make_unique(entity); - break; - } - } - + data->sensor_ = std::make_unique(sensorEntity); if (!data->sensor_) return -EINVAL;