libcamera: Switch PixelFormat to DRM FourCC values
Use DRM FourCC values for the newly defined PixelFormat. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
2a8bf04227
commit
448716d8f7
7 changed files with 58 additions and 46 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <linux/drm_fourcc.h>
|
||||||
#include <linux/media-bus-format.h>
|
#include <linux/media-bus-format.h>
|
||||||
|
|
||||||
#include <libcamera/camera.h>
|
#include <libcamera/camera.h>
|
||||||
|
@ -249,7 +250,7 @@ IPU3CameraConfiguration::IPU3CameraConfiguration(Camera *camera,
|
||||||
void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale)
|
void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale)
|
||||||
{
|
{
|
||||||
/* The only pixel format the driver supports is NV12. */
|
/* The only pixel format the driver supports is NV12. */
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_NV12;
|
cfg.pixelFormat = DRM_FORMAT_NV12;
|
||||||
|
|
||||||
if (scale) {
|
if (scale) {
|
||||||
/*
|
/*
|
||||||
|
@ -404,7 +405,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
|
||||||
StreamConfiguration cfg = {};
|
StreamConfiguration cfg = {};
|
||||||
IPU3Stream *stream = nullptr;
|
IPU3Stream *stream = nullptr;
|
||||||
|
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_NV12;
|
cfg.pixelFormat = DRM_FORMAT_NV12;
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case StreamRole::StillCapture:
|
case StreamRole::StillCapture:
|
||||||
|
@ -1121,7 +1122,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
V4L2DeviceFormat outputFormat = {};
|
V4L2DeviceFormat outputFormat = {};
|
||||||
outputFormat.fourcc = V4L2_PIX_FMT_NV12;
|
outputFormat.fourcc = dev->toV4L2Fourcc(DRM_FORMAT_NV12);
|
||||||
outputFormat.size = cfg.size;
|
outputFormat.size = cfg.size;
|
||||||
outputFormat.planesCount = 2;
|
outputFormat.planesCount = 2;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
#include <linux/drm_fourcc.h>
|
||||||
#include <linux/media-bus-format.h>
|
#include <linux/media-bus-format.h>
|
||||||
|
|
||||||
#include <ipa/rkisp1.h>
|
#include <ipa/rkisp1.h>
|
||||||
|
@ -434,14 +435,14 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera,
|
||||||
CameraConfiguration::Status RkISP1CameraConfiguration::validate()
|
CameraConfiguration::Status RkISP1CameraConfiguration::validate()
|
||||||
{
|
{
|
||||||
static const std::array<unsigned int, 8> formats{
|
static const std::array<unsigned int, 8> formats{
|
||||||
V4L2_PIX_FMT_YUYV,
|
DRM_FORMAT_YUYV,
|
||||||
V4L2_PIX_FMT_YVYU,
|
DRM_FORMAT_YVYU,
|
||||||
V4L2_PIX_FMT_VYUY,
|
DRM_FORMAT_VYUY,
|
||||||
V4L2_PIX_FMT_NV16,
|
DRM_FORMAT_NV16,
|
||||||
V4L2_PIX_FMT_NV61,
|
DRM_FORMAT_NV61,
|
||||||
V4L2_PIX_FMT_NV21,
|
DRM_FORMAT_NV21,
|
||||||
V4L2_PIX_FMT_NV12,
|
DRM_FORMAT_NV12,
|
||||||
V4L2_PIX_FMT_GREY,
|
/* \todo Add support for 8-bit greyscale to DRM formats */
|
||||||
};
|
};
|
||||||
|
|
||||||
const CameraSensor *sensor = data_->sensor_;
|
const CameraSensor *sensor = data_->sensor_;
|
||||||
|
@ -462,7 +463,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
|
||||||
if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) ==
|
if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) ==
|
||||||
formats.end()) {
|
formats.end()) {
|
||||||
LOG(RkISP1, Debug) << "Adjusting format to NV12";
|
LOG(RkISP1, Debug) << "Adjusting format to NV12";
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_NV12;
|
cfg.pixelFormat = DRM_FORMAT_NV12,
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +542,7 @@ CameraConfiguration *PipelineHandlerRkISP1::generateConfiguration(Camera *camera
|
||||||
return config;
|
return config;
|
||||||
|
|
||||||
StreamConfiguration cfg{};
|
StreamConfiguration cfg{};
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_NV12;
|
cfg.pixelFormat = DRM_FORMAT_NV12;
|
||||||
cfg.size = data->sensor_->resolution();
|
cfg.size = data->sensor_->resolution();
|
||||||
|
|
||||||
config->addConfiguration(cfg);
|
config->addConfiguration(cfg);
|
||||||
|
@ -623,7 +624,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
|
||||||
LOG(RkISP1, Debug) << "ISP output pad configured with " << format.toString();
|
LOG(RkISP1, Debug) << "ISP output pad configured with " << format.toString();
|
||||||
|
|
||||||
V4L2DeviceFormat outputFormat = {};
|
V4L2DeviceFormat outputFormat = {};
|
||||||
outputFormat.fourcc = cfg.pixelFormat;
|
outputFormat.fourcc = video_->toV4L2Fourcc(cfg.pixelFormat);
|
||||||
outputFormat.size = cfg.size;
|
outputFormat.size = cfg.size;
|
||||||
outputFormat.planesCount = 2;
|
outputFormat.planesCount = 2;
|
||||||
|
|
||||||
|
@ -632,7 +633,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (outputFormat.size != cfg.size ||
|
if (outputFormat.size != cfg.size ||
|
||||||
outputFormat.fourcc != cfg.pixelFormat) {
|
outputFormat.fourcc != video_->toV4L2Fourcc(cfg.pixelFormat)) {
|
||||||
LOG(RkISP1, Error)
|
LOG(RkISP1, Error)
|
||||||
<< "Unable to configure capture in " << cfg.toString();
|
<< "Unable to configure capture in " << cfg.toString();
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -176,7 +176,7 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
V4L2DeviceFormat format = {};
|
V4L2DeviceFormat format = {};
|
||||||
format.fourcc = cfg.pixelFormat;
|
format.fourcc = data->video_->toV4L2Fourcc(cfg.pixelFormat);
|
||||||
format.size = cfg.size;
|
format.size = cfg.size;
|
||||||
|
|
||||||
ret = data->video_->setFormat(&format);
|
ret = data->video_->setFormat(&format);
|
||||||
|
@ -184,7 +184,7 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (format.size != cfg.size ||
|
if (format.size != cfg.size ||
|
||||||
format.fourcc != cfg.pixelFormat)
|
format.fourcc != data->video_->toV4L2Fourcc(cfg.pixelFormat))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
cfg.setStream(&data->stream_);
|
cfg.setStream(&data->stream_);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
#include <linux/drm_fourcc.h>
|
||||||
#include <linux/media-bus-format.h>
|
#include <linux/media-bus-format.h>
|
||||||
|
|
||||||
#include <ipa/ipa_interface.h>
|
#include <ipa/ipa_interface.h>
|
||||||
|
@ -106,9 +107,9 @@ private:
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr std::array<unsigned int, 3> pixelformats{
|
constexpr std::array<unsigned int, 3> pixelformats{
|
||||||
V4L2_PIX_FMT_BGR24,
|
DRM_FORMAT_RGB888,
|
||||||
V4L2_PIX_FMT_RGB24,
|
DRM_FORMAT_BGR888,
|
||||||
V4L2_PIX_FMT_ARGB32,
|
DRM_FORMAT_BGRA8888,
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace */
|
} /* namespace */
|
||||||
|
@ -137,7 +138,7 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()
|
||||||
if (std::find(pixelformats.begin(), pixelformats.end(), cfg.pixelFormat) ==
|
if (std::find(pixelformats.begin(), pixelformats.end(), cfg.pixelFormat) ==
|
||||||
pixelformats.end()) {
|
pixelformats.end()) {
|
||||||
LOG(VIMC, Debug) << "Adjusting format to RGB24";
|
LOG(VIMC, Debug) << "Adjusting format to RGB24";
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_RGB24;
|
cfg.pixelFormat = DRM_FORMAT_BGR888;
|
||||||
status = Adjusted;
|
status = Adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,
|
||||||
|
|
||||||
StreamConfiguration cfg(formats.data());
|
StreamConfiguration cfg(formats.data());
|
||||||
|
|
||||||
cfg.pixelFormat = V4L2_PIX_FMT_RGB24;
|
cfg.pixelFormat = DRM_FORMAT_BGR888;
|
||||||
cfg.size = { 1920, 1080 };
|
cfg.size = { 1920, 1080 };
|
||||||
cfg.bufferCount = 4;
|
cfg.bufferCount = 4;
|
||||||
|
|
||||||
|
@ -231,7 +232,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
V4L2DeviceFormat format = {};
|
V4L2DeviceFormat format = {};
|
||||||
format.fourcc = cfg.pixelFormat;
|
format.fourcc = data->video_->toV4L2Fourcc(cfg.pixelFormat);
|
||||||
format.size = cfg.size;
|
format.size = cfg.size;
|
||||||
|
|
||||||
ret = data->video_->setFormat(&format);
|
ret = data->video_->setFormat(&format);
|
||||||
|
@ -239,7 +240,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (format.size != cfg.size ||
|
if (format.size != cfg.size ||
|
||||||
format.fourcc != cfg.pixelFormat)
|
format.fourcc != data->video_->toV4L2Fourcc(cfg.pixelFormat))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -19,8 +19,10 @@ namespace libcamera {
|
||||||
* \brief libcamera image pixel format
|
* \brief libcamera image pixel format
|
||||||
*
|
*
|
||||||
* The PixelFormat type describes the format of images in the public libcamera
|
* The PixelFormat type describes the format of images in the public libcamera
|
||||||
* API. It stores a FourCC value in a 32-bit unsigned integer. The values are
|
* API. It stores a FourCC value as a 32-bit unsigned integer. The values are
|
||||||
* defined in the Linux kernel V4L2 API (see linux/videodev2.h).
|
* defined in the Linux kernel DRM/KMS API (see linux/drm_fourcc.h).
|
||||||
|
*
|
||||||
|
* \todo Add support for format modifiers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <linux/videodev2.h>
|
#include <linux/drm_fourcc.h>
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
|
@ -31,84 +31,84 @@ int FormatConverter::configure(unsigned int format, unsigned int width,
|
||||||
unsigned int height)
|
unsigned int height)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case V4L2_PIX_FMT_NV12:
|
case DRM_FORMAT_NV12:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 2;
|
horzSubSample_ = 2;
|
||||||
vertSubSample_ = 2;
|
vertSubSample_ = 2;
|
||||||
nvSwap_ = false;
|
nvSwap_ = false;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_NV21:
|
case DRM_FORMAT_NV21:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 2;
|
horzSubSample_ = 2;
|
||||||
vertSubSample_ = 2;
|
vertSubSample_ = 2;
|
||||||
nvSwap_ = true;
|
nvSwap_ = true;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_NV16:
|
case DRM_FORMAT_NV16:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 2;
|
horzSubSample_ = 2;
|
||||||
vertSubSample_ = 1;
|
vertSubSample_ = 1;
|
||||||
nvSwap_ = false;
|
nvSwap_ = false;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_NV61:
|
case DRM_FORMAT_NV61:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 2;
|
horzSubSample_ = 2;
|
||||||
vertSubSample_ = 1;
|
vertSubSample_ = 1;
|
||||||
nvSwap_ = true;
|
nvSwap_ = true;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_NV24:
|
case DRM_FORMAT_NV24:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 1;
|
horzSubSample_ = 1;
|
||||||
vertSubSample_ = 1;
|
vertSubSample_ = 1;
|
||||||
nvSwap_ = false;
|
nvSwap_ = false;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_NV42:
|
case DRM_FORMAT_NV42:
|
||||||
formatFamily_ = NV;
|
formatFamily_ = NV;
|
||||||
horzSubSample_ = 1;
|
horzSubSample_ = 1;
|
||||||
vertSubSample_ = 1;
|
vertSubSample_ = 1;
|
||||||
nvSwap_ = true;
|
nvSwap_ = true;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_BGR24:
|
case DRM_FORMAT_RGB888:
|
||||||
formatFamily_ = RGB;
|
formatFamily_ = RGB;
|
||||||
r_pos_ = 2;
|
r_pos_ = 2;
|
||||||
g_pos_ = 1;
|
g_pos_ = 1;
|
||||||
b_pos_ = 0;
|
b_pos_ = 0;
|
||||||
bpp_ = 3;
|
bpp_ = 3;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_RGB24:
|
case DRM_FORMAT_BGR888:
|
||||||
formatFamily_ = RGB;
|
formatFamily_ = RGB;
|
||||||
r_pos_ = 0;
|
r_pos_ = 0;
|
||||||
g_pos_ = 1;
|
g_pos_ = 1;
|
||||||
b_pos_ = 2;
|
b_pos_ = 2;
|
||||||
bpp_ = 3;
|
bpp_ = 3;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_ARGB32:
|
case DRM_FORMAT_BGRA8888:
|
||||||
formatFamily_ = RGB;
|
formatFamily_ = RGB;
|
||||||
r_pos_ = 1;
|
r_pos_ = 1;
|
||||||
g_pos_ = 2;
|
g_pos_ = 2;
|
||||||
b_pos_ = 3;
|
b_pos_ = 3;
|
||||||
bpp_ = 4;
|
bpp_ = 4;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_VYUY:
|
case DRM_FORMAT_VYUY:
|
||||||
formatFamily_ = YUV;
|
formatFamily_ = YUV;
|
||||||
y_pos_ = 1;
|
y_pos_ = 1;
|
||||||
cb_pos_ = 2;
|
cb_pos_ = 2;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_YVYU:
|
case DRM_FORMAT_YVYU:
|
||||||
formatFamily_ = YUV;
|
formatFamily_ = YUV;
|
||||||
y_pos_ = 0;
|
y_pos_ = 0;
|
||||||
cb_pos_ = 3;
|
cb_pos_ = 3;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_UYVY:
|
case DRM_FORMAT_UYVY:
|
||||||
formatFamily_ = YUV;
|
formatFamily_ = YUV;
|
||||||
y_pos_ = 1;
|
y_pos_ = 1;
|
||||||
cb_pos_ = 0;
|
cb_pos_ = 0;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_YUYV:
|
case DRM_FORMAT_YUYV:
|
||||||
formatFamily_ = YUV;
|
formatFamily_ = YUV;
|
||||||
y_pos_ = 0;
|
y_pos_ = 0;
|
||||||
cb_pos_ = 1;
|
cb_pos_ = 1;
|
||||||
break;
|
break;
|
||||||
case V4L2_PIX_FMT_MJPEG:
|
case DRM_FORMAT_MJPEG:
|
||||||
formatFamily_ = MJPEG;
|
formatFamily_ = MJPEG;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -155,7 +155,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool done() const { return done_; }
|
bool done() const { return done_; }
|
||||||
const V4L2DeviceFormat &format() const { return format_; }
|
|
||||||
|
PixelFormat format() const
|
||||||
|
{
|
||||||
|
return video_->toPixelFormat(format_.fourcc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Size &size() const
|
||||||
|
{
|
||||||
|
return format_.size;
|
||||||
|
}
|
||||||
|
|
||||||
Signal<uint64_t, int> requestReady;
|
Signal<uint64_t, int> requestReady;
|
||||||
|
|
||||||
|
@ -314,11 +323,9 @@ protected:
|
||||||
return TestFail;
|
return TestFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
const V4L2DeviceFormat &format = sink_.format();
|
|
||||||
|
|
||||||
StreamConfiguration &cfg = config->at(0);
|
StreamConfiguration &cfg = config->at(0);
|
||||||
cfg.size = format.size;
|
cfg.size = sink_.size();
|
||||||
cfg.pixelFormat = format.fourcc;
|
cfg.pixelFormat = sink_.format();
|
||||||
cfg.bufferCount = CAMERA_BUFFER_COUNT;
|
cfg.bufferCount = CAMERA_BUFFER_COUNT;
|
||||||
cfg.memoryType = ExternalMemory;
|
cfg.memoryType = ExternalMemory;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue