From patchwork Fri Apr 23 04:07:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12092 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 02BA5BDB15 for ; Fri, 23 Apr 2021 04:07:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B4CA368872; Fri, 23 Apr 2021 06:07:51 +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="fj2iZxD+"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D42468861 for ; Fri, 23 Apr 2021 06:07:48 +0200 (CEST) Received: by mail-pj1-x1032.google.com with SMTP id f6-20020a17090a6546b029015088cf4a1eso549347pjs.2 for ; Thu, 22 Apr 2021 21:07:48 -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=aYyEl85BGRXcwUXnJTysQs2J8kpH0ejwtwgIxJEe4R0=; b=fj2iZxD+b/Zg1Xpmuc3liLpcPsT0rti+ts1MUZHHJVM6xZshVSK8eSLbK6+Dftyavc 2VD3nBgc4on801FcEbZvcxOJfj5DDRShDOHI4BIpa3qOtnQPTQv5es+SL2NCCLQEMZ2f MoAAf8VjyrEsGWRNjbKBz5ZDN/4yxm/IGzpXI= 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=aYyEl85BGRXcwUXnJTysQs2J8kpH0ejwtwgIxJEe4R0=; b=Hi6aIf6O9wDhuSNYmeiuK8jWX3BAhuqaGUpVIw6iZPBemOC8FPYbS8XVvpDlAH70ho kf1AwxW0AUlaAMogckl68PnRxIMopFFsN1GTebgH8kR7YLGcQelMNaUHNJdJsn09mhyy AR1/PE9VRXYqgLTkRi+8xh9ubtOLSByLqjsj7v4ZnaegwlM/0gh9ZXk1aq3cGGmiZrCT jHKSEUXwi8L/b2PeQMzayXLWkywqhXJRpx0L+chrIeCyQ1wX812rLdD41ZSvqXbLmp72 73pG7MGpBU0BN6ZmPCJt2SmDZ2M0e+BzkHrrzL+pL0CZ/s1hYr6fUnce2vwGYYdDURqX /bnQ== X-Gm-Message-State: AOAM532kpwVozRaRBa1v00mZ509br/Dyg+dIkWWdIamfaj59OuQLdR56 g8bOvgLP9XxKJ+L25E7NkTjnQ4PKaT4h+A== X-Google-Smtp-Source: ABdhPJxb2QjyiY0it+Kbs2QjO7c40eJ64FNnzhiqyaymh4/zu+0mfwUfe41rquXdoxv1WNUzH3qs4Q== X-Received: by 2002:a17:90a:a613:: with SMTP id c19mr3579691pjq.117.1619150866680; Thu, 22 Apr 2021 21:07:46 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id j23sm3229670pfh.179.2021.04.22.21.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 21:07:46 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 13:07:38 +0900 Message-Id: <20210423040738.1227220-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog In-Reply-To: <20210423040738.1227220-1-hiroh@chromium.org> References: <20210423040738.1227220-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] android: CameraDevice: Implement HAL3 API flush 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" This implements flush(). It is mostly the same as close() though the canceled events are reported with error messages. Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 41 +++++++++++++++++++++++++++++------ src/android/camera_device.h | 1 + src/android/camera_ops.cpp | 6 ++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c74dc0e7..22a2e13c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -753,6 +753,15 @@ void CameraDevice::close() stop(/*releaseCamera=*/true); } +int CameraDevice::flush() +{ + std::scoped_lock lock(mutex_); + + stop(); + + return 0; +} + void CameraDevice::stop(bool releaseCamera) { streams_.clear(); @@ -770,6 +779,23 @@ void CameraDevice::stop(bool releaseCamera) worker_.stop(); camera_->stop(); + for (auto &[cookie, descriptor] : descriptors_) { + LOG(HAL, Debug) << "request is canceled: " << cookie; + + camera3_capture_result_t captureResult = {}; + captureResult.frame_number = descriptor.frameNumber_; + captureResult.num_output_buffers = descriptor.buffers_.size(); + for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { + buffer.acquire_fence = -1; + buffer.release_fence = -1; + buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + } + captureResult.output_buffers = descriptor.buffers_.data(); + + notifyError(descriptor.frameNumber_, + descriptor.buffers_[0].stream); + callbacks_->process_capture_result(callbacks_, &captureResult); + } descriptors_.clear(); running_ = false; @@ -2128,6 +2154,14 @@ void CameraDevice::requestComplete(Request *request) } if (status == CAMERA3_BUFFER_STATUS_ERROR || !captureResult.result) { + /* + * \todo Report and identify the stream number or configuration + * to clarify the stream that failed. + */ + LOG(HAL, Error) + << "Error occurred on frame " << descriptor.frameNumber_ << " (" + << toPixelFormat(descriptor.buffers_[0].stream->format).toString() << ")"; + /* \todo Improve error handling. In case we notify an error * because the metadata generation fails, a shutter event has * already been notified for this frame number before the error @@ -2161,13 +2195,6 @@ void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream) { camera3_notify_msg_t notify = {}; - /* - * \todo Report and identify the stream number or configuration to - * clarify the stream that failed. - */ - LOG(HAL, Error) << "Error occurred on frame " << frameNumber << " (" - << toPixelFormat(stream->format).toString() << ")"; - notify.type = CAMERA3_MSG_ERROR; notify.message.error.error_stream = stream; notify.message.error.frame_number = frameNumber; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 08553584..7004c89a 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -41,6 +41,7 @@ public: int open(const hw_module_t *hardwareModule); void close(); + int flush(); unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } diff --git a/src/android/camera_ops.cpp b/src/android/camera_ops.cpp index 696e8043..981a3d30 100644 --- a/src/android/camera_ops.cpp +++ b/src/android/camera_ops.cpp @@ -68,7 +68,11 @@ static void hal_dev_dump([[maybe_unused]] const struct camera3_device *dev, static int hal_dev_flush([[maybe_unused]] const struct camera3_device *dev) { - return 0; + if (!dev) + return -EINVAL; + + CameraDevice *camera = reinterpret_cast(dev->priv); + return camera->flush(); } int hal_dev_close(hw_device_t *hw_device)