From patchwork Tue Dec 14 14:00:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15162 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 4016BC324B for ; Tue, 14 Dec 2021 14:00:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 75700608E9; Tue, 14 Dec 2021 15:00:08 +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="PPLxMMEN"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 26060605A7 for ; Tue, 14 Dec 2021 15:00:06 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id q3so32525906wru.5 for ; Tue, 14 Dec 2021 06:00:06 -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=nJnkmgQAsgdErldvbjoJq1Zg/UvxAKQrj2jHEwu8eT0=; b=PPLxMMENoV8N2lsMpvxiDXW7KTHgu3lffwJph5bUG58afeDRWbN9FwsqTqeRK4djl1 ybz5kT9Idx77FYZ0NGFlDtNFbEvAiFHKRLOEl6/5JpBE4ygQSJAwDGbiNYxh2DGEgRav yPiar+CuevjDZjm3s9jc2Q7nJHkZ+egMckrFREd1YAiskX7hzZogNahzb9f9DPs1KmjT u96ZQwBkafzQQsFhXbr+P33l6RW7fGUbS4NBvPG77cVzDvO0BPBtvUQwYfGy90OqZSxh ljwOWs9fPquQG4CU9TmPu1ZHln4m8J6DCwpZD9G3B+IG/ZDFseSeW9IZI3fUudP9Zx9x XIUA== 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=nJnkmgQAsgdErldvbjoJq1Zg/UvxAKQrj2jHEwu8eT0=; b=W4PRnQvfXZ+6jbU4fQ2UTAkrUSv9oLfu5bVKMPsP6CQe9oNI7F5MgtwiicoFhjygNf fJ46/PFxQdkkqfWKwdBwQX1Y9aFT1eAqviJEY7qBZp3OsBsXwk9JVH4aqi0orf0k6gP1 PgEwZZJ3fpvGHvo9vLUc73THCh5AfYDF9+gqImmqmNVI1a5P2iNDm1+Ffa6F4iH0AE1I vT0rfVNakq356jCeSZCSfcq2uyxss15HsWR0zNZN1qyQAFHgbShmng4VRTMob9ZeaRHJ 70iJOYj7HL2ZYyjSInbwmBjmKMLRRCNOQOgBd3nO+wVmFmmq6WyRF1Ssy/tFKMvy1leP rwEA== X-Gm-Message-State: AOAM5323ZywqrXmWPWQXks5YaWDgsTYx0ioUWAW2u4AazjijyuolG03V Zz2FQYAKE6DkEMCMqLHEDxGk5C5wpiV/qg== X-Google-Smtp-Source: ABdhPJw96eQYEM1X7ZoDNzFfRAa6S8jHoJyrLwoI0IdF8HAVZb3IyreLbhnrfbgdkYZUmjphls1e+A== X-Received: by 2002:a5d:6c67:: with SMTP id r7mr5853527wrz.286.1639490405659; Tue, 14 Dec 2021 06:00:05 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:8958:60a:582a:396]) by smtp.gmail.com with ESMTPSA id m7sm2160999wml.38.2021.12.14.06.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Dec 2021 06:00:05 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Dec 2021 14:00:01 +0000 Message-Id: <20211214140002.3552445-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214140002.3552445-1-naush@raspberrypi.com> References: <20211214140002.3552445-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- .../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 86851ac467ad..2a2fb5273eb8 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -310,7 +310,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); @@ -1029,16 +1029,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 attached 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); @@ -1079,14 +1091,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;