From patchwork Tue Jun 15 08:00:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12595 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 63D8CC3218 for ; Tue, 15 Jun 2021 08:00:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CB47468943; Tue, 15 Jun 2021 10:00:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hytvBuuY"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 35EA360299 for ; Tue, 15 Jun 2021 10:00:46 +0200 (CEST) Received: by mail-pj1-x1031.google.com with SMTP id k22-20020a17090aef16b0290163512accedso1387317pjz.0 for ; Tue, 15 Jun 2021 01:00:46 -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:mime-version :content-transfer-encoding; bh=B38Iqh22cRNogGkfOzk/XrL6JtFZ+jfTy/WOVaP5r8M=; b=hytvBuuYBMySRDmgTvj+rMTL4NlZeQV48yaFZbK8WjCOWk1+NWWExJmsBcHixDgru1 CEb7nIhuGwW/gcQOd1dGbseOpbOtmwwUyacergamY5+fxtYdQRJCXnktB5PrIXR8qQCy gBZtNo8DAkmHeIi0m1w07H0NaRRE5c6d/Kii0= 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:mime-version :content-transfer-encoding; bh=B38Iqh22cRNogGkfOzk/XrL6JtFZ+jfTy/WOVaP5r8M=; b=NPnGPDkibTRI4m6Ib9I4vRWSHjxj5U0WgJN0riPWYfIXARWVCaf6/NYrYbah1OVLJc y4osIPknlsSYuIwaf/5ioNd1v8LdMezBnQsLdPwAEsn09MK1tzHmX89as9i9ieWMHXoe mrBl2hWaPfs03M3yITtouq61f8l6Oe881eu1G+TVR4Hhntwtnv0DVJJXLM/3DPh4UtLW 1aelotx01y3pL+VW2OEJXrJE+raNbmsznAblV8AYfnFTQ4K02t3GDKuy8PsGZjd9VqRw ilzznrDqJOsECb8BapuMa0qQMc5VbzsaJWrQv3AWoDdiMETP0i1+5VRIl2gXUf4go7iG PHsA== X-Gm-Message-State: AOAM531s9Y9ZT6PukkWfnKQncXWfaLjKOeNRDJ38JQb6HTaBZLjz58MQ jWnz+O+uI9ogS9xtShytYJnA+5ZREl5kdg== X-Google-Smtp-Source: ABdhPJxdbENRwQD6J65dSuz8CqtDu5JjITp66hiov0VcAFCIOHFaeESXaTulbS0nVyl4S5a0HrGaCw== X-Received: by 2002:a17:902:ceca:b029:112:b67b:fe4f with SMTP id d10-20020a170902cecab0290112b67bfe4fmr1592652plg.32.1623744044040; Tue, 15 Jun 2021 01:00:44 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3a3f:22c6:a48a:9392]) by smtp.gmail.com with ESMTPSA id k18sm1823296pff.63.2021.06.15.01.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 01:00:43 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jun 2021 17:00:28 +0900 Message-Id: <20210615080028.2270177-1-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] android: camera_device: Check if a request is configured on processCaptureRequest() 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" Add a check on processCaptureRequest() if a given capture request contains a camera stream that has been configured. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 108 +++++++++++++++++++++------------- src/android/camera_device.h | 1 + 2 files changed, 67 insertions(+), 42 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f3fd3869..a117a904 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -10,6 +10,7 @@ #include "camera_ops.h" #include "post_processor.h" +#include #include #include #include @@ -260,48 +261,6 @@ void sortCamera3StreamConfigs(std::vector &unsortedConfigs, unsortedConfigs = sortedConfigs; } -bool isValidRequest(camera3_capture_request_t *camera3Request) -{ - if (!camera3Request) { - LOG(HAL, Error) << "No capture request provided"; - return false; - } - - if (!camera3Request->num_output_buffers || - !camera3Request->output_buffers) { - LOG(HAL, Error) << "No output buffers provided"; - return false; - } - - for (uint32_t i = 0; i < camera3Request->num_output_buffers; i++) { - const camera3_stream_buffer_t &outputBuffer = - camera3Request->output_buffers[i]; - if (!outputBuffer.buffer || !(*outputBuffer.buffer)) { - LOG(HAL, Error) << "Invalid native handle"; - return false; - } - - const native_handle_t *handle = *outputBuffer.buffer; - constexpr int kNativeHandleMaxFds = 1024; - if (handle->numFds < 0 || handle->numFds > kNativeHandleMaxFds) { - LOG(HAL, Error) - << "Invalid number of fds (" << handle->numFds - << ") in buffer " << i; - return false; - } - - constexpr int kNativeHandleMaxInts = 1024; - if (handle->numInts < 0 || handle->numInts > kNativeHandleMaxInts) { - LOG(HAL, Error) - << "Invalid number of ints (" << handle->numInts - << ") in buffer " << i; - return false; - } - } - - return true; -} - const char *rotationToString(int rotation) { switch (rotation) { @@ -1979,6 +1938,71 @@ void CameraDevice::abortRequest(camera3_capture_request_t *request) callbacks_->process_capture_result(callbacks_, &result); } +bool CameraDevice::isValidRequest(camera3_capture_request_t *camera3Request) const +{ + if (!camera3Request) { + LOG(HAL, Error) << "No capture request provided"; + return false; + } + + if (!camera3Request->num_output_buffers || + !camera3Request->output_buffers) { + LOG(HAL, Error) << "No output buffers provided"; + return false; + } + + /* configureStreams() has not been called or has failed. */ + if (streams_.empty() || !config_) { + LOG(HAL, Error) << "No stream is configured"; + return false; + } + + for (uint32_t i = 0; i < camera3Request->num_output_buffers; i++) { + const camera3_stream_buffer_t &outputBuffer = + camera3Request->output_buffers[i]; + if (!outputBuffer.buffer || !(*outputBuffer.buffer)) { + LOG(HAL, Error) << "Invalid native handle"; + return false; + } + + const native_handle_t *handle = *outputBuffer.buffer; + constexpr int kNativeHandleMaxFds = 1024; + if (handle->numFds < 0 || handle->numFds > kNativeHandleMaxFds) { + LOG(HAL, Error) + << "Invalid number of fds (" << handle->numFds + << ") in buffer " << i; + return false; + } + + constexpr int kNativeHandleMaxInts = 1024; + if (handle->numInts < 0 || handle->numInts > kNativeHandleMaxInts) { + LOG(HAL, Error) + << "Invalid number of ints (" << handle->numInts + << ") in buffer " << i; + return false; + } + + const camera3_stream *camera3Stream = outputBuffer.stream; + if (!camera3Stream) + return false; + + const CameraStream *cameraStream = + static_cast(camera3Stream->priv); + + auto found = std::find_if(streams_.begin(), streams_.end(), + [cameraStream](const CameraStream &stream) { + return &stream == cameraStream; + }); + if (found == streams_.end()) { + LOG(HAL, Error) + << "No corresponding configured stream found"; + return false; + } + } + + return true; +} + int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { if (!isValidRequest(camera3Request)) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 4aadb27c..4d9c904d 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -109,6 +109,7 @@ private: libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void abortRequest(camera3_capture_request_t *request); + bool isValidRequest(camera3_capture_request_t *request) const; void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream, camera3_error_msg_code code);