From dccc998ecf580e5c41b290a60e6b6f170601dc29 Mon Sep 17 00:00:00 2001 From: sw.multimedia Date: Wed, 15 Dec 2021 17:13:58 +0800 Subject: [PATCH] support use yaml file to config sensor pipeline --- src/libcamera/meson.build | 3 + .../pipeline/starfive/sensors_pipeline.yaml | 35 ++++++ src/libcamera/pipeline/starfive/starfive.cpp | 106 ++++++++++++++++-- 3 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 src/libcamera/pipeline/starfive/sensors_pipeline.yaml diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 6727a777..39c44d42 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -113,6 +113,8 @@ if ipa_sign_module libcamera_sources += ipa_pub_key_cpp endif +libyamlcpp = cc.find_library('yaml-cpp', required : true) + libcamera_deps = [ libatomic, libcamera_base, @@ -121,6 +123,7 @@ libcamera_deps = [ libgnutls, liblttng, libudev, + libyamlcpp, ] # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag. diff --git a/src/libcamera/pipeline/starfive/sensors_pipeline.yaml b/src/libcamera/pipeline/starfive/sensors_pipeline.yaml new file mode 100644 index 00000000..3446b0ac --- /dev/null +++ b/src/libcamera/pipeline/starfive/sensors_pipeline.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# Copyright (C) 2020, Google Inc. +# +%YAML 1.2 +# description: +# sensors: +# - sensorentity: "imx219 0-0010" +# ispfwimage: "stf_isp0_fw_dump.bin" isp fw image name +# sensortype: 4 +# +# sensortype value: +# { +# DVP_YUV = 0, +# MIPICSI0_YUV = 1, +# MIPICSI1_YUV = 2, +# DVP_ISP0 = 3, // ISP0 +# MIPICSI0_ISP0 = 4, +# MIPICSI1_ISP0 = 5, +# DVP_ISP1 = 6, // ISP1 +# MIPICSI0_ISP1 = 7, +# MIPICSI1_ISP1 = 8, +# SENSORTYPE_MAX +# } +# +--- +sensors: + - sensorentity: "imx219 0-0010" + ispfwimage: "stf_isp0_fw_dump.bin" + sensortype: 4 + + - sensorentity: "imx219 2-0010" + ispfwimage: "stf_isp0_fw_dump.bin" + sensortype: 8 +... diff --git a/src/libcamera/pipeline/starfive/starfive.cpp b/src/libcamera/pipeline/starfive/starfive.cpp index bb513387..8afe5e89 100644 --- a/src/libcamera/pipeline/starfive/starfive.cpp +++ b/src/libcamera/pipeline/starfive/starfive.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -40,14 +42,7 @@ #define STF_MAX_CAMERAS 3 -namespace libcamera { - -LOG_DEFINE_CATEGORY(STARFIVE) - -static constexpr unsigned int BUFFER_COUNT = 4; -static constexpr unsigned int MAX_STREAMS = 2; -static const Size OUTPUT_MIN_SIZE = { 8, 8 }; -static const Size OUTPUT_MAX_SIZE = { 8192, 8192 }; +#define PIPELINE_CONFIG_FILENAME "/root/sensors_pipeline.yaml" namespace { @@ -67,14 +62,16 @@ typedef enum { typedef struct { std::string sensorEntityName_; std::string sensorFwImageName_; - SensorType sensorType_; + int sensorType_; } SensorConfig; -const std::vector sensorConfigs = { +const std::vector defaultSensorConfigs = { { "imx219 0-0010", "stf_isp0_fw_dump.bin", MIPICSI0_ISP0 }, { "imx219 2-0010", "stf_isp0_fw_dump.bin", MIPICSI1_ISP1 }, }; +std::vector sensorConfigs; + typedef struct { std::string source; std::string link; @@ -140,6 +137,40 @@ const std::vector pipelineConfigs[SENSORTYPE_MAX] = { mipicsi1raw1Config, }; +} /* namespace */ + +namespace YAML { + template<> + struct convert { + static Node encode(const SensorConfig& sensor) { + Node node; + node.push_back(sensor.sensorEntityName_); + node.push_back(sensor.sensorFwImageName_); + node.push_back(sensor.sensorType_); + return node; + } + + static bool decode(const Node& node, SensorConfig& sensor) { + if(node.size() != 3) + return false; + + sensor.sensorEntityName_ = node["sensorentity"].as(); + sensor.sensorFwImageName_ = node["ispfwimage"].as(); + sensor.sensorType_ = node["sensortype"].as(); + return true; + } + }; +} + +namespace libcamera { + +LOG_DEFINE_CATEGORY(STARFIVE) + +static constexpr unsigned int BUFFER_COUNT = 4; +static constexpr unsigned int MAX_STREAMS = 2; +static const Size OUTPUT_MIN_SIZE = { 8, 8 }; +static const Size OUTPUT_MAX_SIZE = { 8192, 8192 }; + const std::map mbusCodesToPixelFormat = { { MEDIA_BUS_FMT_SBGGR10_1X10, formats::SBGGR12 }, { MEDIA_BUS_FMT_SGBRG10_1X10, formats::SGBRG12 }, @@ -147,8 +178,6 @@ const std::map mbusCodesToPixelFormat = { { MEDIA_BUS_FMT_SRGGB10_1X10, formats::SRGGB12 }, }; -} /* namespace */ - class StarFiveCameraData : public Camera::Private { public: @@ -424,6 +453,7 @@ private: int enableLinks(std::vector config); MediaDevice *starFiveMediaDev_; + int parserPipelineConfig(const char *filename); }; StarFiveCameraConfiguration::StarFiveCameraConfiguration(StarFiveCameraData *data) @@ -1044,6 +1074,56 @@ int PipelineHandlerStarFive::enableLinks(std::vector config) return ret; } +static void loaddefaultSensorConfig(void) +{ + LOG(STARFIVE, Debug) << __func__; + sensorConfigs.clear(); + for (SensorConfig it : defaultSensorConfigs) + sensorConfigs.push_back(it); +} + +static void printSensorConfig(void) +{ + for (SensorConfig it : sensorConfigs) + LOG(STARFIVE, Debug) + << " sensorEntityName: " << it.sensorEntityName_ + << ", ispLoadFW: " << it.sensorFwImageName_ + << ", sensorType: " << it.sensorType_; +} + +int PipelineHandlerStarFive::parserPipelineConfig(const char *filename) +{ + LOG(STARFIVE, Debug) << __func__; + try { + YAML::Node config = YAML::LoadFile(PIPELINE_CONFIG_FILENAME); + + if (config["sensors"]) { + std::vector sensors = + config["sensors"].as>(); + int found = 0; + + for (SensorConfig it : sensors) { + found = 0; + for (SensorConfig its : sensorConfigs) { + if (its.sensorEntityName_ == it.sensorEntityName_) { + found = 1; + break; + } + } + if (!found) + sensorConfigs.push_back(it); + } + } + } catch(std::exception const & e) { + LOG(STARFIVE, Debug) << PIPELINE_CONFIG_FILENAME + << " yaml file error, use default config!!!"; + loaddefaultSensorConfig(); + } + + printSensorConfig(); + return 0; +} + bool PipelineHandlerStarFive::match(DeviceEnumerator *enumerator) { int numCameras = 0; @@ -1061,6 +1141,8 @@ bool PipelineHandlerStarFive::match(DeviceEnumerator *enumerator) if (starFiveMediaDev_->disableLinks()) return false; + parserPipelineConfig(PIPELINE_CONFIG_FILENAME); + for (SensorConfig it : sensorConfigs) { MediaEntity *sensorEntity = starFiveMediaDev_->getEntityByName(it.sensorEntityName_); -- 2.17.1