From patchwork Mon Jun 14 06:03:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12579 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 25747BD78E for ; Mon, 14 Jun 2021 06:03:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 955BB60297; Mon, 14 Jun 2021 08:03:19 +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="V2Lmmae1"; dkim-atps=neutral Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9389760297 for ; Mon, 14 Jun 2021 08:03:16 +0200 (CEST) Received: by mail-pf1-x431.google.com with SMTP id x73so9735022pfc.8 for ; Sun, 13 Jun 2021 23:03:16 -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=6ESIk4OGCxodVIKa0LlH9gHL2Jgk4Za1DflAec8BqV8=; b=V2Lmmae16XGtANLwyLWuR7TZRaI/hBQTcGHvieafNzYUTSdcW2RnKMZWjK1D06E2PY 4Of6ilemI8GF+75L0t1uFifQ2t+kCHomBOSvcP7A5KdZZ0ba7fTWWtzjJcmRCmxfIT/t J1eJPhOsw3nZD5q7Bb9nAClaZQnkRTDIkfG58= 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=6ESIk4OGCxodVIKa0LlH9gHL2Jgk4Za1DflAec8BqV8=; b=krlnXXfwiHjD2TuxF0rIL0sGTMUgJvj13zAOteHwI9mfElN2C6uWcwb9EdgMNxPBIr bdju0Fp1gFX1QtZ14fIOOysIndUl+z+AWYL6H/WI8Hx2f30yMVtntO5SIV8Tp/xi2U3I fOlKrih9BZQ4D37Xq24eZiLZlUQ9ywZKpd6vhV+vpS3DkOy9XtTB7d7g1I0FvrNR2uLf xFBsqsgPLnt/wbToTojSEChN4eKrbuzxLi/Xso/3c2cEnUv9ZcM8QkXDUqGOuuowoMx+ p+SD5Jl//+FDoPCcXLR9y3QDie9phD5fSwOSwOIy6FChB+yda6xcwOJJkpMuTPkUcZfA F9Cw== X-Gm-Message-State: AOAM532ZrpTc63xCycvXZuxHg1OEHVFH/cj9bYvEG2F4V7oTUxuDABZq O4QSGMsqFWmTpIR6RfcKTFDK2RME48CuGA== X-Google-Smtp-Source: ABdhPJwkcb5tDjAw3DJvr8LUkRUx7KpesXeU8ZpRYGq/n3XKoLWWfCKWMnV/JvrHXv5sNKW+fxIvZA== X-Received: by 2002:aa7:96e3:0:b029:2ec:e8a1:3d66 with SMTP id i3-20020aa796e30000b02902ece8a13d66mr20141661pfq.79.1623650594413; Sun, 13 Jun 2021 23:03:14 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:dd3f:f6f0:e98e:863b]) by smtp.gmail.com with ESMTPSA id z8sm12301577pgi.94.2021.06.13.23.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Jun 2021 23:03:13 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 14 Jun 2021 15:03:03 +0900 Message-Id: <20210614060303.2405391-1-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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" Adds 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 | 111 +++++++++++++++++++++------------- src/android/camera_device.h | 1 + 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3adb657b..5b182257 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -260,48 +260,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) { @@ -1934,6 +1892,75 @@ 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() is not called or fails. + 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); + + bool found = false; + for (const CameraStream &stream : streams_) { + if (&stream == cameraStream) { + found = true; + break; + } + } + + if (!found) { + 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);