diff options
author | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-06-26 09:58:49 +0100 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-07-06 23:58:42 +0100 |
commit | 43e3b8002bad0e4f7b74132975285cb10c6b8a60 (patch) | |
tree | 01ac6c8d494b34a4c5f50b9fffd284c8b5b6510a /src/android/camera_device.cpp | |
parent | d35cf6e4e4972948e49e6e45f3f0caaeea760a0b (diff) |
android: camera_device: Provide a toPixelFormat helper
Rather than converting pixelformats through the map, and then
dereferencing the iterator later, create a helper to explicitly return a
PixelFormat type.
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/android/camera_device.cpp')
-rw-r--r-- | src/android/camera_device.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f788c11e..b9031ff0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -923,6 +923,19 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) return requestTemplate->get(); } +PixelFormat CameraDevice::toPixelFormat(int format) +{ + /* Translate Android format code to libcamera pixel format. */ + auto it = formatsMap_.find(format); + if (it == formatsMap_.end()) { + LOG(HAL, Error) << "Requested format " << utils::hex(format) + << " not supported"; + return PixelFormat(); + } + + return it->second; +} + /* * Inspect the stream_list to produce a list of StreamConfiguration to * be use to configure the Camera. @@ -932,11 +945,14 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; + PixelFormat format = toPixelFormat(stream->format); + LOG(HAL, Info) << "Stream #" << i << ", direction: " << stream->stream_type << ", width: " << stream->width << ", height: " << stream->height - << ", format: " << utils::hex(stream->format); + << ", format: " << utils::hex(stream->format) + << " (" << format.toString() << ")"; } /* Only one stream is supported. */ @@ -947,13 +963,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) camera3_stream_t *camera3Stream = stream_list->streams[0]; /* Translate Android format code to libcamera pixel format. */ - auto it = formatsMap_.find(camera3Stream->format); - if (it == formatsMap_.end()) { - LOG(HAL, Error) << "Requested format " - << utils::hex(camera3Stream->format) - << " not supported"; + PixelFormat format = toPixelFormat(camera3Stream->format); + if (!format.isValid()) return -EINVAL; - } /* * Hardcode viewfinder role, replacing the generated configuration @@ -969,7 +981,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) StreamConfiguration *streamConfiguration = &config_->at(0); streamConfiguration->size.width = camera3Stream->width; streamConfiguration->size.height = camera3Stream->height; - streamConfiguration->pixelFormat = it->second; + streamConfiguration->pixelFormat = format; switch (config_->validate()) { case CameraConfiguration::Valid: |