From patchwork Tue May 26 14:22:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3866 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1218461075 for ; Tue, 26 May 2020 16:19:28 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from localhost.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 6426C40002; Tue, 26 May 2020 14:19:28 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 26 May 2020 16:22:36 +0200 Message-Id: <20200526142237.407557-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526142237.407557-1-jacopo@jmondi.org> References: <20200526142237.407557-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/8] android: camera_device: Translate Android format 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: , X-List-Received-Date: Tue, 26 May 2020 14:19:30 -0000 Translate the Android format code to the libcamera format code at stream configuration time, using the translation map built at camera device initialization time. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f8a52342abe5..b0f5a6a2edb5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -904,12 +904,27 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) << ", format: " << utils::hex(stream->format); } - /* Hardcode viewfinder role, collecting sizes from the stream config. */ + /* 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 format code. */ + auto it = formatsMap_.find(camera3Stream->format); + if (it == formatsMap_.end()) { + LOG(HAL, Error) << "Requested format " + << utils::hex(camera3Stream->format) + << " not supported"; + return -EINVAL; + } + uint32_t libcameraFormatCode = it->second; + /* + * Hardcode viewfinder role, replacing the generate configuration + * parameters with the Android framework requestes ones. + */ StreamRoles roles = { StreamRole::Viewfinder }; config_ = camera_->generateConfiguration(roles); if (!config_ || config_->empty()) { @@ -917,17 +932,10 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return -EINVAL; } - /* Only one stream is supported. */ - camera3_stream_t *camera3Stream = stream_list->streams[0]; StreamConfiguration *streamConfiguration = &config_->at(0); streamConfiguration->size.width = camera3Stream->width; streamConfiguration->size.height = camera3Stream->height; - - /* - * \todo We'll need to translate from Android defined pixel format codes - * to the libcamera image format codes. For now, do not change the - * format returned from Camera::generateConfiguration(). - */ + streamConfiguration->pixelFormat = PixelFormat(libcameraFormatCode); switch (config_->validate()) { case CameraConfiguration::Valid: