From patchwork Tue Jan 4 12:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15243 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 C936CC3258 for ; Tue, 4 Jan 2022 12:57:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 671886092F; Tue, 4 Jan 2022 13:57: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="ChhKve4S"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 04D44604F4 for ; Tue, 4 Jan 2022 13:57:17 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id p1-20020a1c7401000000b00345c2d068bdso20139909wmc.3 for ; Tue, 04 Jan 2022 04:57:17 -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=isbLew+Hfz3OpvSyqfWQp0MtX+L2fQ4xOz39/GgziQQ=; b=ChhKve4SPkNEedsSBhMdCHBx5YIxKVm+SUjemYATuT4M7+tyebaUtp3GUp1a1glUTo GXS0AsOhJABIPsRBst2yAMXJm3Ow/nWmO9Fj0hw0MVtlpqyVZ6mUSqkRdjscTpAWg11B ycFQnFwvq9IU3sVvI73X6AmhMD3ZZ5SV0MP2iw+CNZhodky8zxAN0+WrhSDaujrOSYOH f91KrLHb73lVtVAGnQnvJx+L00nR3ghWuwWGKNVoJ3ba7moWIvQ7pSBLd10HhJmZRvEy +YUwcSc0vkspWJnBvnWfG/wXMPLTAltJ8JSjf0/Ak4g0q5Vc4SEBFSUKTHs/tLPVoWYv ygLg== 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=isbLew+Hfz3OpvSyqfWQp0MtX+L2fQ4xOz39/GgziQQ=; b=2MoYHtIwuxwSVSO5buMT6tPd94EB7+bL/4Xpkgh76OXTk2Ndvqnh1nTJ34Va6k9KPh ampPcqGCwbylH67dgEuoyeAAdGSkQ6zhIERFQ+U4xGAgttrZey7rP67X/Ud1KZJXq90E S+FdG4it5jxMYCnKQzdNGQu0Z9dKu1iTx5vXrMWOO26MkjRoyDcc/aZlGJsgfAaIdmZ9 TSO9E+zro+LsAB56ButiZN+GIcZNe44ES/muhKWkXbSSgjF7kZFue2KdjavZySKHYcRX G1U6BY+JRSKOVb+dL9aM6YZJVaK6S0R+C6OxHB6wUg6qvMigPGAh97CLFo9EWcfQR9nC tKWQ== X-Gm-Message-State: AOAM5326tS29EJ6UyIWKbFf4rC9jpJMUXVSvIlJLx39+8VtqA5yY9xqb G5qKdE3K2OHEkFbgOYxhWrbOMBBSfEaVmg== X-Google-Smtp-Source: ABdhPJzegxBGYBEIqKtylSQQNFA7M1i84Oo1F3oP6o3JAwnTyXRotEutTBcpFveu0SPq7x/0PbXZSg== X-Received: by 2002:a7b:c007:: with SMTP id c7mr42423899wmb.27.1641301036525; Tue, 04 Jan 2022 04:57:16 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:cf71:3c12:f0dd:e082]) by smtp.gmail.com with ESMTPSA id p15sm35673753wmj.46.2022.01.04.04.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 04:57:16 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Jan 2022 12:57:08 +0000 Message-Id: <20220104125709.1273546-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104125709.1273546-1-naush@raspberrypi.com> References: <20220104125709.1273546-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 b5c687da467f..a6d1e8570abf 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -312,7 +312,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); @@ -1069,16 +1069,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); @@ -1119,14 +1131,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;