From patchwork Wed Jul 6 09:22:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 16560 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 D9931BE173 for ; Wed, 6 Jul 2022 09:22:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8660063315; Wed, 6 Jul 2022 11:22:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657099343; bh=Qqxl+tZPoLNBl5IGNN12T5kzRZ/OaFUmuu0d85KdJ3w=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pHWZ+cce3CI9IpESGm1DW3m1Prwct0R2r5+xqSgiSAwoD4dhpmHxIViuwL2jFX3hq B1UZA1htpT5qrKvC14qm3NjqFc+FoC0bVg6FCVXFbxh7evk5A4vNMPQDE7Mgkcw5J8 qy1aLq6a4IQiEBJSNMASG/YWhV+E/sdE1lOdAiCUj/xjcEGjl13W58GH1/ba4VkXNJ d5oVxV4yGCKY24AclZHr8CyE3WoSff100PjGOybJKbZSfcotRA+TRAsh4Acj+D6+1X XwYppPysy5KmIOOm2u7inAH9DH67Pr+NxnZtW5V4uCxwm4KLSLnoQZoZAiR4YFIwSW JLozdvaS/HVTg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 888F86330F for ; Wed, 6 Jul 2022 11:22:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="dkBjWWHv"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E19AF30A; Wed, 6 Jul 2022 11:22:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657099342; bh=Qqxl+tZPoLNBl5IGNN12T5kzRZ/OaFUmuu0d85KdJ3w=; h=From:To:Cc:Subject:Date:From; b=dkBjWWHvhgJ/FW8ddETkUx01hbr+tC7ntuv2jt52Zrz1ZS5lXDEC/miSbgvI568EG QMiGJVyg1KIv8yRwisZGyigcQD22DKu6xjIqAEVdmU+1OHHEZ7CH8cnQtSrP/DWoV3 nYH73WmkEsb+FPrUaQ9/LjEwpXFIp1iUs7L+NitQ= To: libcamera devel Date: Wed, 6 Jul 2022 10:22:18 +0100 Message-Id: <20220706092218.2761216-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH] qcam: Fix IPU3 camera switching 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" On the IPU3 we will disallow acquiring a second camera while one is active. This prevents us from doing a camera switch between the available cameras. Re-instate this facility by ensuring we release the current camera before attempting to acquire the new camera. Signed-off-by: Kieran Bingham --- QCam is broken on IPU3 in that once one camera is running, we can't swap to the other without closing qcam (or swapping to a non IPU3 camera). This seems a bit of a pain - but here's a potential fix. Since writing this patch (some time ago) I know think that trying to reaquire the previous camera if the switch fails might be wrong. I wonder if we should just leave the camera halted, with our 'no-image' logo displayed, and wait. But the only way to 'fix' this would be for the user to choose a new camera, there's no current option to retry acquiring a camera... src/qcam/main_window.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7433d647e8a0..487f522748ca 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -269,11 +269,6 @@ void MainWindow::switchCamera(int index) const std::shared_ptr &cam = cameras[index]; - if (cam->acquire()) { - qInfo() << "Failed to acquire camera" << cam->id().c_str(); - return; - } - qInfo() << "Switching to camera" << cam->id().c_str(); /* @@ -283,7 +278,26 @@ void MainWindow::switchCamera(int index) startStopAction_->setChecked(false); camera_->release(); - camera_ = cam; + + /* + * Only attempt to acquire after releasing to ensure we support + * pipelines which can only stream from one device at a time. + * + * Todo: Consider how we could acquire more than one camera + * but ensure only one could stream at a time. + */ + if (cam->acquire()) { + qInfo() << "Failed to acquire camera" << cam->id().c_str(); + qInfo() << "Switching back to " << camera_->id().c_str(); + + if (camera_->acquire()) { + qInfo() << "Failed to reacquire " << camera_->id().c_str(); + return; + } + } else { + /* Acquire was successful, Switch to this camera */ + camera_ = cam; + } startStopAction_->setChecked(true); }