From patchwork Mon Mar 29 17:40:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phi-bang Nguyen X-Patchwork-Id: 11774 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 3DFDAC32F0 for ; Mon, 29 Mar 2021 17:41:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8A9B268784; Mon, 29 Mar 2021 19:41:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="c8oHUHUV"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B86C06877D for ; Mon, 29 Mar 2021 19:41:11 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so8878325wma.0 for ; Mon, 29 Mar 2021 10:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=09oRVhxdPvd5qx78k0wVXXFF+9FLjhHM2pVPVQWlYtQ=; b=c8oHUHUVppETposVzbP1eIgLIc1Bf2YEcJjW5zakF7Q9FaqUYLL1rZRXNCNVRdYA8T qJI8sUd9JaOpzNgTlXBmNdHuNcU9+ADbExJjnSa+E5J9REX7hAwOnzq0PYMTA7f3h26I LdTrxszp7g7tB01+X69JXPRdqGvmewJwP5j7arKyy6Eu/fQLtKuVKO2ZfXijds9+ozTV 8Bbx7qyVZjrdroejGOCt3Qt5oxl4zMzCxbyZWs+5Ha9HiQMXiIj4y3ef+xGQJDo4qtJI tYMGykFwlI0JDiL/4daqD6+rFqfqo6/iIOh3WfwPTOR767XAtCx/mHRCoQ3eFNYUxU+h JAMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=09oRVhxdPvd5qx78k0wVXXFF+9FLjhHM2pVPVQWlYtQ=; b=b3yB/BlMhqYgh2OH5sfCzq0rLAkcXvp/DGWY+9zLHewwsqejUDm3JYSfvpc0CuGzB6 SLjjBCQegKF6TL91Q52q+wrCHcT+SabBEVV8tV5XZENmPxwRoKj/Ojv4v62/nawXin+c LchKaC+6TKyresQ358Kwki4LUL2ERsSOHLIGPIJd/JY+zgC7cs/p1nfIs6zAE6FRqXoW YMILmsc/7FbLtS+1B/0uz171L/IhqYh7EMfAnvMzex2AqCG6GH9V1vnryi4CIUsCSjPQ XbnAOdHUzwe7MdMY4XajR1ovX/9732nuX9UgnGYLgpmVeylUwEpaJaEr1WbSy0zOTvu6 8igA== X-Gm-Message-State: AOAM5318x4NLVjYUzvXXNp29eAWUyeo1z+pKfpUaazdeTJSFdqZsJMdU DRtrMEhTvTKM9NrZPtfnd8KrI5dn6OPRGg== X-Google-Smtp-Source: ABdhPJw5TzCdzgJrJktUaTM2jVpWb/0dGMjiNnP8q6raH+mmXdnbdsefFMS/oBrDwN0ToNj+1gWu9A== X-Received: by 2002:a7b:c3c1:: with SMTP id t1mr207521wmj.47.1617039671091; Mon, 29 Mar 2021 10:41:11 -0700 (PDT) Received: from localhost.localdomain (206.159.69.91.rev.sfr.net. [91.69.159.206]) by smtp.googlemail.com with ESMTPSA id b65sm144368wmh.4.2021.03.29.10.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 10:41:10 -0700 (PDT) From: Phi-Bang Nguyen To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Mar 2021 19:40:46 +0200 Message-Id: <20210329174046.86591-1-pnguyen@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] android: camera_device: Add null check for ScalerCrop control 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" The ScalerCrop control does not contain the null check which can cause the camera HAL crash at boot. Fix it. Fixes: 31a1a628cd0e ("android: camera_device: Register MAX_DIGITAL_ZOOM") Signed-off-by: Phi-Bang Nguyen Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index ae693664..9ec261c3 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1095,26 +1095,28 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() } /* Scaler static metadata. */ - { - /* - * \todo The digital zoom factor is a property that depends - * on the desired output configuration and the sensor frame size - * input to the ISP. This information is not available to the - * Android HAL, not at initialization time at least. - * - * As a workaround rely on pipeline handlers initializing the - * ScalerCrop control with the camera default configuration and - * use the maximum and minimum crop rectangles to calculate the - * digital zoom factor. - */ - const auto info = controlsInfo.find(&controls::ScalerCrop); - Rectangle min = info->second.min().get(); - Rectangle max = info->second.max().get(); - float maxZoom = std::min(1.0f * max.width / min.width, - 1.0f * max.height / min.height); - staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, - &maxZoom, 1); + + /* + * \todo The digital zoom factor is a property that depends + * on the desired output configuration and the sensor frame size + * input to the ISP. This information is not available to the + * Android HAL, not at initialization time at least. + * + * As a workaround rely on pipeline handlers initializing the + * ScalerCrop control with the camera default configuration and + * use the maximum and minimum crop rectangles to calculate the + * digital zoom factor. + */ + float maxZoom = 1.0f; + const auto scalerCrop = controlsInfo.find(&controls::ScalerCrop); + if (scalerCrop != controlsInfo.end()) { + Rectangle min = scalerCrop->second.min().get(); + Rectangle max = scalerCrop->second.max().get(); + maxZoom = std::min(1.0f * max.width / min.width, + 1.0f * max.height / min.height); } + staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, + &maxZoom, 1); std::vector availableStreamConfigurations; availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);