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>
This commit is contained in:
parent
d35cf6e4e4
commit
43e3b8002b
2 changed files with 21 additions and 8 deletions
|
@ -923,6 +923,19 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)
|
||||||
return requestTemplate->get();
|
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
|
* Inspect the stream_list to produce a list of StreamConfiguration to
|
||||||
* be use to configure the Camera.
|
* 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) {
|
for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
|
||||||
camera3_stream_t *stream = stream_list->streams[i];
|
camera3_stream_t *stream = stream_list->streams[i];
|
||||||
|
|
||||||
|
PixelFormat format = toPixelFormat(stream->format);
|
||||||
|
|
||||||
LOG(HAL, Info) << "Stream #" << i
|
LOG(HAL, Info) << "Stream #" << i
|
||||||
<< ", direction: " << stream->stream_type
|
<< ", direction: " << stream->stream_type
|
||||||
<< ", width: " << stream->width
|
<< ", width: " << stream->width
|
||||||
<< ", height: " << stream->height
|
<< ", height: " << stream->height
|
||||||
<< ", format: " << utils::hex(stream->format);
|
<< ", format: " << utils::hex(stream->format)
|
||||||
|
<< " (" << format.toString() << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only one stream is supported. */
|
/* 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];
|
camera3_stream_t *camera3Stream = stream_list->streams[0];
|
||||||
|
|
||||||
/* Translate Android format code to libcamera pixel format. */
|
/* Translate Android format code to libcamera pixel format. */
|
||||||
auto it = formatsMap_.find(camera3Stream->format);
|
PixelFormat format = toPixelFormat(camera3Stream->format);
|
||||||
if (it == formatsMap_.end()) {
|
if (!format.isValid())
|
||||||
LOG(HAL, Error) << "Requested format "
|
|
||||||
<< utils::hex(camera3Stream->format)
|
|
||||||
<< " not supported";
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hardcode viewfinder role, replacing the generated configuration
|
* 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 *streamConfiguration = &config_->at(0);
|
||||||
streamConfiguration->size.width = camera3Stream->width;
|
streamConfiguration->size.width = camera3Stream->width;
|
||||||
streamConfiguration->size.height = camera3Stream->height;
|
streamConfiguration->size.height = camera3Stream->height;
|
||||||
streamConfiguration->pixelFormat = it->second;
|
streamConfiguration->pixelFormat = format;
|
||||||
|
|
||||||
switch (config_->validate()) {
|
switch (config_->validate()) {
|
||||||
case CameraConfiguration::Valid:
|
case CameraConfiguration::Valid:
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
|
std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
|
||||||
void notifyShutter(uint32_t frameNumber, uint64_t timestamp);
|
void notifyShutter(uint32_t frameNumber, uint64_t timestamp);
|
||||||
void notifyError(uint32_t frameNumber, camera3_stream_t *stream);
|
void notifyError(uint32_t frameNumber, camera3_stream_t *stream);
|
||||||
|
libcamera::PixelFormat toPixelFormat(int format);
|
||||||
std::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,
|
std::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,
|
||||||
int64_t timestamp);
|
int64_t timestamp);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue