From patchwork Mon Jun 29 16:39:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8514 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 C423EBFFE2 for ; Mon, 29 Jun 2020 16:39:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B9E360AFF; Mon, 29 Jun 2020 18:39:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="M3qo4M/b"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CF9C6609DB for ; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 69AC3734; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593448761; bh=2diS92rUVzZmaoS2xhsb+2exXlUEV3EBcAhvWMDMEEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3qo4M/b8uKaENRl3irwHmKgizEd3qyWxn6s56Vb9+kxQzqM5BPSvnNgCCqYwBSOa sB9uBPaALonlnE7OXHjVR0Peqp0ttXZd+b0mhTuvgH9yZEgKwKK2Jmv0e5wL3ipk1i rrXWoBUpdyCHQrBChhau+2uieLGmrqJfdOa+45p8= From: Kieran Bingham To: libcamera devel Date: Mon, 29 Jun 2020 17:39:16 +0100 Message-Id: <20200629163916.1815321-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> References: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] android: camera_device: support multiple stream configurations 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" Create an initial Camera Configuration using an empty role set, and populate the StreamConfigurations manually from each of the streams given by the Android camera3_stream_configuration_t stream_list. Signed-off-by: Kieran Bingham --- src/android/camera_device.cpp | 72 ++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a6410f42fee8..568ba28067d0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -956,48 +956,52 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) << " (" << format.toString() << ")"; } - /* Only one stream is supported. */ - if (stream_list->num_streams != 1) { - LOG(HAL, Error) << "Only one stream supported"; - return -EINVAL; - } - camera3_stream_t *camera3Stream = stream_list->streams[0]; - - /* Translate Android format code to libcamera pixel format. */ - PixelFormat format = toPixelFormat(camera3Stream->format); - if (!format.isValid()) - return -EINVAL; - /* - * Hardcode viewfinder role, replacing the generated configuration - * parameters with the ones requested by the Android framework. + * Generate an empty configuration, and construct a StreamConfiguration + * for each camera3_stream to add to it. */ - StreamRoles roles = { StreamRole::Viewfinder }; - config_ = camera_->generateConfiguration(roles); - if (!config_ || config_->empty()) { + config_ = camera_->generateConfiguration(); + if (!config_) { LOG(HAL, Error) << "Failed to generate camera configuration"; return -EINVAL; } - StreamConfiguration *streamConfiguration = &config_->at(0); - streamConfiguration->size.width = camera3Stream->width; - streamConfiguration->size.height = camera3Stream->height; - streamConfiguration->pixelFormat = format; + for (unsigned int i = 0; i < stream_list->num_streams; ++i) { + camera3_stream_t *stream = stream_list->streams[i]; - switch (config_->validate()) { - case CameraConfiguration::Valid: - break; - case CameraConfiguration::Adjusted: - LOG(HAL, Info) << "Camera configuration adjusted"; - config_.reset(); - return -EINVAL; - case CameraConfiguration::Invalid: - LOG(HAL, Info) << "Camera configuration invalid"; - config_.reset(); - return -EINVAL; - } + PixelFormat format = toPixelFormat(stream->format); + if (!format.isValid()) + return -EINVAL; + + StreamConfiguration streamConfiguration; + + streamConfiguration.size.width = stream->width; + streamConfiguration.size.height = stream->height; + streamConfiguration.pixelFormat = format; + + StreamConfiguration &cfg = config_->addConfiguration(streamConfiguration); + + /* 'cfg' can be modifed during the validation process */ + CameraConfiguration::Status status = config_->validate(); + + LOG(HAL, Info) << "Stream #" << i << " (validated): " << cfg.toString(); - camera3Stream->max_buffers = streamConfiguration->bufferCount; + switch (status) { + case CameraConfiguration::Valid: + break; + case CameraConfiguration::Adjusted: + LOG(HAL, Info) << "Camera configuration adjusted"; + config_.reset(); + return -EINVAL; + case CameraConfiguration::Invalid: + LOG(HAL, Info) << "Camera configuration invalid"; + config_.reset(); + return -EINVAL; + } + + /* Use the bufferCount confirmed by the validation process. */ + stream->max_buffers = cfg.bufferCount; + } /* * Once the CameraConfiguration has been adjusted/validated