From patchwork Tue Mar 23 01:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11651 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 72783C32E2 for ; Tue, 23 Mar 2021 01:42:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26FCB68D79; Tue, 23 Mar 2021 02:42:48 +0100 (CET) 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="M2bOfA7D"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 279C968D75 for ; Tue, 23 Mar 2021 02:42:46 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id bt4so9355971pjb.5 for ; Mon, 22 Mar 2021 18:42: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=MRorFuuW+i3Eudcvysm6sAexmlSUngopmtWCo+wVBpo=; b=M2bOfA7D4sd+8LR7GzMsvxHgjTNMgZSTcX7tldWcxGUrrXYOeFnb/TvttaZkII1vTS eVBEKfki40D6Dd96V1kK5ZkNxszbKuU4oSAu+9Qzjw8ggrGPpRi5CVHAjk45T4K1HFao BiFxJ3jNuKJbQEFxfeA///k09BeRAbg2SXNI0= 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=MRorFuuW+i3Eudcvysm6sAexmlSUngopmtWCo+wVBpo=; b=hcQJzfdlBEx4uaWACl3CDTJyzZB9g2C0d0m8FKFqT1kgOf1ITUvrhhELB2zPwfNifS 0O8GdCq8m3gdJl92WNTPymbYUBpV3MD/ZjakqG4af7sehXqPHj5CN49Vyeda4QKuYBP2 FOUMXHAQuBspCzmbagYdYzKbU9ZBLZwf3mXKDQPcqqCLcZNnBA6JLWNylzXH00SQva3G 0veAOqHQXjrkmOVYkJ7mxQb8r/v5YvqD6DakDgIn6PowhD2Mj0pPAjxSL0MI3tCNVxBN QcwUWwHXqSJeFlEkLI73CTp+rrWHXLXnTd+lqFsVySzjP2miPZ8akzggbrrd9JXLQC2+ k6SQ== X-Gm-Message-State: AOAM533uuSIFYXJuxJlq59LKnKlNSCJelhktvOvNGCL83TC5orLqoWVt 6XFYgOZSrV5ioVxvKKoMvTpkNfuBfY/u5w== X-Google-Smtp-Source: ABdhPJxaJfZ1sg4s3TQNYxjedgNtNPMAjpP5Uh0ARaclMNSV+osdgtbLowCjG0MdOrtOoUfqXqJ3EQ== X-Received: by 2002:a17:90a:c588:: with SMTP id l8mr1868881pjt.120.1616463764598; Mon, 22 Mar 2021 18:42:44 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8115:e5cc:747b:64de]) by smtp.gmail.com with ESMTPSA id h13sm590527pjv.52.2021.03.22.18.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:44 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:24 +0900 Message-Id: <20210323014226.3211412-7-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog In-Reply-To: <20210323014226.3211412-1-hiroh@chromium.org> References: <20210323014226.3211412-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] android: Camera3RequestDescriptor: Manage buffers with std::vector 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" Camera3RequestDescriptor has a length and an allocated buffer for camera_stream_buffer_t array. This replaces the variables with std::vector. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 37 +++++++++++++++-------------------- src/android/camera_device.h | 3 +-- 2 files changed, 17 insertions(+), 23 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c0630e53..b000d332 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -271,16 +271,16 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( frameNumber_ = camera3Request->frame_number; /* Copy the camera3 request stream information for later access. */ - numBuffers_ = camera3Request->num_output_buffers; - buffers_ = new camera3_stream_buffer_t[numBuffers_]; - for (unsigned int i = 0; i < numBuffers_; ++i) + const uint32_t numBuffers = camera3Request->num_output_buffers; + buffers_.resize(numBuffers); + for (uint32_t i = 0; i < numBuffers; i++) buffers_[i] = camera3Request->output_buffers[i]; /* * FrameBuffer instances created by wrapping a camera3 provided dmabuf * are emplaced in this vector of unique_ptr<> for lifetime management. */ - frameBuffers_.reserve(numBuffers_); + frameBuffers_.reserve(numBuffers); /* Clone the controls associated with the camera3 request. */ settings_ = CameraMetadata(camera3Request->settings); @@ -294,10 +294,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( reinterpret_cast(this)); } -CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() -{ - delete[] buffers_; -} +CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() = default; /* * \class CameraDevice @@ -1840,10 +1837,10 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->settings_ = lastSettings_; LOG(HAL, Debug) << "Queueing request " << descriptor->request_->cookie() - << " with " << descriptor->numBuffers_ << " streams"; - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { - const camera3_stream_buffer_t *camera3Buffer = &descriptor->buffers_[i]; - camera3_stream *camera3Stream = camera3Buffer->stream; + << " with " << descriptor->buffers_.size() << " streams"; + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { + const camera3_stream_buffer_t &camera3Buffer = descriptor->buffers_[i]; + camera3_stream *camera3Stream = camera3Buffer.stream; CameraStream *cameraStream = static_cast(camera3Stream->priv); std::stringstream ss; @@ -1874,7 +1871,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - buffer = createFrameBuffer(*camera3Buffer->buffer); + buffer = createFrameBuffer(*camera3Buffer.buffer); descriptor->frameBuffers_.emplace_back(buffer); LOG(HAL, Debug) << ss.str() << " (direct)"; break; @@ -1899,7 +1896,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques } descriptor->request_->addBuffer(cameraStream->stream(), buffer, - camera3Buffer->acquire_fence); + camera3Buffer.acquire_fence); } /* @@ -1930,7 +1927,7 @@ void CameraDevice::requestComplete(Request *request) } LOG(HAL, Debug) << "Request " << request->cookie() << " completed with " - << descriptor->numBuffers_ << " streams"; + << descriptor->buffers_.size() << " streams"; /* * \todo The timestamp used for the metadata is currently always taken @@ -1942,7 +1939,7 @@ void CameraDevice::requestComplete(Request *request) resultMetadata = getResultMetadata(descriptor, timestamp); /* Handle any JPEG compression. */ - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { CameraStream *cameraStream = static_cast(descriptor->buffers_[i].stream->priv); @@ -1975,15 +1972,13 @@ void CameraDevice::requestComplete(Request *request) /* Prepare to call back the Android camera stack. */ camera3_capture_result_t captureResult = {}; captureResult.frame_number = descriptor->frameNumber_; - captureResult.num_output_buffers = descriptor->numBuffers_; - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { + captureResult.num_output_buffers = descriptor->buffers_.size(); + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { descriptor->buffers_[i].acquire_fence = -1; descriptor->buffers_[i].release_fence = -1; descriptor->buffers_[i].status = status; } - captureResult.output_buffers = - const_cast(descriptor->buffers_); - + captureResult.output_buffers = descriptor->buffers_.data(); if (status == CAMERA3_BUFFER_STATUS_OK) { notifyShutter(descriptor->frameNumber_, timestamp); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 14e26b4d..a11cf243 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -74,8 +74,7 @@ private: ~Camera3RequestDescriptor(); uint32_t frameNumber_; - uint32_t numBuffers_; - camera3_stream_buffer_t *buffers_; + std::vector buffers_; std::vector> frameBuffers_; CameraMetadata settings_; std::unique_ptr request_;