From patchwork Tue Aug 2 10:29:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 16901 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 557FBC3276 for ; Tue, 2 Aug 2022 10:29:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B7C316330E; Tue, 2 Aug 2022 12:29:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659436194; bh=K+d5Jo6cNsZjUngIlCIyJUfRNsIoGQk31HD1Z6KeIJ0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=TIiPR2MF6bz+mk1Mt2dBIpyY7i3q4cQjQNtSuLzDAiPWFO69dgxrDlfm+pLpg0570 HwOSlHYFzDsDrUODZ/nZ1HTTYohdTR6/3PzmKRQWbkAaCF6tQUxf8M7Htp+O0bsHJ9 m4ckG6BhV/BKkTWA9Vd0aLcwj3w5XjIzLJZnKUlQ5T+BlZcCeCcJAfm9otgb7G8EJ8 aysq9AdHXInJrWgRmeesPsToQ0CTMliguxDXKljujwlasYNe4wbHWzCy7apmkYVmki QyZLlQ6gyNFCh2d8Q5kY15wIoXt1Wy9NvVlnFGGG+K3GdHmV/qdl930sNknOaSF1kW 8YQhrwDF9ytpw== Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD22F603E7 for ; Tue, 2 Aug 2022 12:29:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Yu1+A24U"; dkim-atps=neutral Received: by mail-pg1-x52b.google.com with SMTP id bh13so11996132pgb.4 for ; Tue, 02 Aug 2022 03:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AEuPodY8SqK4FTOvnbJG9NYQfsr6wvmyDvFxGw5IoUs=; b=Yu1+A24UVJvubefo9indYLi9H/wJrHrRHHetheIwJyb1i58MlOHpujAe1/j2Ik6Yhr 4g0FPYPLjOhfhDpnF3O5iCAaQqykJEbQWOj9bah13rfF58m/5SA8NNJU0wH3V5wNQxZF 2/NQ1UofnWoR1tlPXtrmRrCoQWpF/ztCftF2s= 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=AEuPodY8SqK4FTOvnbJG9NYQfsr6wvmyDvFxGw5IoUs=; b=UInPYUeSBjR1ztttwudzBDi9Oxsy2Aewj0Zh1zG8fmqtOl9VJoIAn7F3znvSft63sl Acg7uAdDxQxsIhOGtvHVoAdOg5p76p+Bdtjn8DILOI1rQUAU4nMO/BGWvn4EVc+xK4iL YdfLihN/eeqe1XXk2Gtyy6QkP3OhQqfFh4awCAwN7WsB2cZItHbv7s+cJCodBGVgLZ08 1sxtYDL/EEo/fFj+0aisjLd5n6eAlZNXg7+TM5G3rcgst81rPM2heTD6huGIH1H9oEAK ahfRV+jzRq1hmImWfM8bkyn+zMUCSThYZFgYbdnBVqI/Q3FxjhMEtJHs5KBuyLa+Q/f/ O7IA== X-Gm-Message-State: AJIora/O5ZJt9rLG5VPMX6Nb5hx48CGdSqzwZ6MDKnOctJrp1bZ1CH6D qoJMr8d45YBhsek/qkZSiDKUApfUoihE+w== X-Google-Smtp-Source: AGRyM1sY0reyi3e5V+naC6d9rQ0vJiNdr5F6VyTLQBNLiiIYfdSLCjL9pQmDWRg4xzEaOU2HL7tjhw== X-Received: by 2002:a63:4847:0:b0:419:c8f4:4f88 with SMTP id x7-20020a634847000000b00419c8f44f88mr16081361pgk.603.1659436191773; Tue, 02 Aug 2022 03:29:51 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (231.137.80.34.bc.googleusercontent.com. [34.80.137.231]) by smtp.gmail.com with ESMTPSA id t15-20020a170902e84f00b0016db88f69a2sm1955128plg.141.2022.08.02.03.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 03:29:51 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Aug 2022 10:29:36 +0000 Message-Id: <20220802102943.3221109-3-chenghaoyang@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog In-Reply-To: <20220802102943.3221109-1-chenghaoyang@google.com> References: <20220802102943.3221109-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/9] ipu3: Allow only one camera being started 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: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang As we hardly have use cases/applications that need both cameras at the same time, this patch adds a rule that only one camera can be started one time. This also allows the following patches that use both imgus to process frames from one single camera. Signed-off-by: Harvey Yang --- include/libcamera/internal/pipeline_handler.h | 5 ++++ src/libcamera/camera.cpp | 11 ++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 18 +++++++++++++ src/libcamera/pipeline_handler.cpp | 26 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index c3e4c258..8277ceda 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -55,6 +55,9 @@ public: virtual int exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) = 0; + virtual bool acquire(Camera *camera); + virtual void release(Camera *camera); + virtual int start(Camera *camera, const ControlList *controls) = 0; void stop(Camera *camera); bool hasPendingRequests(const Camera *camera) const; @@ -76,6 +79,8 @@ protected: CameraManager *manager_; + std::set acquiredCameras_; + private: void mediaDeviceDisconnected(MediaDevice *media); virtual void disconnect(); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 713543fd..a31f8769 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -826,6 +826,8 @@ int Camera::exportFrameBuffers(Stream *stream, * \return 0 on success or a negative error code otherwise * \retval -ENODEV The camera has been disconnected from the system * \retval -EBUSY The camera is not free and can't be acquired by the caller + * \retval -EUSERS The maximum number of cameras that can be opened concurrently + * were opened already */ int Camera::acquire() { @@ -845,6 +847,14 @@ int Camera::acquire() return -EBUSY; } + if (!d->pipe_->acquire(this)) { + LOG(Camera, Info) + << "The maximum number of cameras that can be opened" + "concurrently were opened already"; + d->pipe_->unlock(); + return -EUSERS; + } + d->setState(Private::CameraAcquired); return 0; @@ -873,6 +883,7 @@ int Camera::release() if (ret < 0) return ret == -EACCES ? -EBUSY : ret; + d->pipe_->release(this); d->pipe_->unlock(); d->setState(Private::CameraAvailable); diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index fd989e61..091a40e1 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -141,6 +141,8 @@ public: int exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) override; + bool acquire(Camera *camera) override; + int start(Camera *camera, const ControlList *controls) override; void stopDevice(Camera *camera) override; @@ -763,8 +765,24 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera) return 0; } +bool PipelineHandlerIPU3::acquire(Camera *camera) { + /* + * Enforce that only a single camera can be used at a time to use both + * ImgUs on the camera, so that StillCapture stream can adopt another + * set of configuration. + */ + if (!acquiredCameras_.empty()) + return false; + + return PipelineHandler::acquire(camera); + +} + int PipelineHandlerIPU3::start(Camera *camera, [[maybe_unused]] const ControlList *controls) { + if (acquiredCameras_.empty() || *acquiredCameras_.begin() != camera) + return -EUSERS; + IPU3CameraData *data = cameraData(camera); CIO2Device *cio2 = &data->cio2_; ImgUDevice *imgu = data->imgu_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 7ebd76ad..fff9ee59 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -270,6 +270,32 @@ void PipelineHandler::unlock() * otherwise */ +/** + * \fn PipelineHandler::acquire() + * \brief Check if \a camera can be acquired and supported with the current + * pipeline handler usage. If \a camera has already been acquired (by the same + * or another process), return false. + * \param[in] camera The camera + */ +bool PipelineHandler::acquire(Camera *camera) +{ + if (acquiredCameras_.find(camera) != acquiredCameras_.end()) + return false; + + acquiredCameras_.emplace(camera); + return true; +} + +/** + * \fn PipelineHandler::release() + * \brief Release exclusive access to \a camera + * \param[in] camera The camera + */ +void PipelineHandler::release(Camera *camera) +{ + acquiredCameras_.erase(camera); +} + /** * \fn PipelineHandler::start() * \brief Start capturing from a group of streams