0008-support-use-yaml-file-to-config-sensor-pipeline.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. From 4c51694d5f3fbb23423f60165f928e50e7d9c3a3 Mon Sep 17 00:00:00 2001
  2. From: sw.multimedia <sw.multimedia@starfivetech.com>
  3. Date: Wed, 15 Dec 2021 17:13:58 +0800
  4. Subject: [PATCH 08/10] support use yaml file to config sensor pipeline
  5. ---
  6. src/libcamera/meson.build | 3 +
  7. .../pipeline/starfive/sensors_pipeline.yaml | 35 ++++++
  8. src/libcamera/pipeline/starfive/starfive.cpp | 106 ++++++++++++++++--
  9. 3 files changed, 132 insertions(+), 12 deletions(-)
  10. create mode 100644 src/libcamera/pipeline/starfive/sensors_pipeline.yaml
  11. diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
  12. index 6727a777..39c44d42 100644
  13. --- a/src/libcamera/meson.build
  14. +++ b/src/libcamera/meson.build
  15. @@ -113,6 +113,8 @@ if ipa_sign_module
  16. libcamera_sources += ipa_pub_key_cpp
  17. endif
  18. +libyamlcpp = cc.find_library('yaml-cpp', required : true)
  19. +
  20. libcamera_deps = [
  21. libatomic,
  22. libcamera_base,
  23. @@ -121,6 +123,7 @@ libcamera_deps = [
  24. libgnutls,
  25. liblttng,
  26. libudev,
  27. + libyamlcpp,
  28. ]
  29. # We add '/' to the build_rpath as a 'safe' path to act as a boolean flag.
  30. diff --git a/src/libcamera/pipeline/starfive/sensors_pipeline.yaml b/src/libcamera/pipeline/starfive/sensors_pipeline.yaml
  31. new file mode 100644
  32. index 00000000..3446b0ac
  33. --- /dev/null
  34. +++ b/src/libcamera/pipeline/starfive/sensors_pipeline.yaml
  35. @@ -0,0 +1,35 @@
  36. +# SPDX-License-Identifier: LGPL-2.1-or-later
  37. +#
  38. +# Copyright (C) 2020, Google Inc.
  39. +#
  40. +%YAML 1.2
  41. +# description:
  42. +# sensors:
  43. +# - sensorentity: "imx219 0-0010"
  44. +# ispfwimage: "stf_isp0_fw_dump.bin" isp fw image name
  45. +# sensortype: 4
  46. +#
  47. +# sensortype value:
  48. +# {
  49. +# DVP_YUV = 0,
  50. +# MIPICSI0_YUV = 1,
  51. +# MIPICSI1_YUV = 2,
  52. +# DVP_ISP0 = 3, // ISP0
  53. +# MIPICSI0_ISP0 = 4,
  54. +# MIPICSI1_ISP0 = 5,
  55. +# DVP_ISP1 = 6, // ISP1
  56. +# MIPICSI0_ISP1 = 7,
  57. +# MIPICSI1_ISP1 = 8,
  58. +# SENSORTYPE_MAX
  59. +# }
  60. +#
  61. +---
  62. +sensors:
  63. + - sensorentity: "imx219 0-0010"
  64. + ispfwimage: "stf_isp0_fw_dump.bin"
  65. + sensortype: 4
  66. +
  67. + - sensorentity: "imx219 2-0010"
  68. + ispfwimage: "stf_isp0_fw_dump.bin"
  69. + sensortype: 8
  70. +...
  71. diff --git a/src/libcamera/pipeline/starfive/starfive.cpp b/src/libcamera/pipeline/starfive/starfive.cpp
  72. index b91a85a4..864addfa 100644
  73. --- a/src/libcamera/pipeline/starfive/starfive.cpp
  74. +++ b/src/libcamera/pipeline/starfive/starfive.cpp
  75. @@ -9,6 +9,8 @@
  76. #include <queue>
  77. #include <sys/mman.h>
  78. #include <math.h>
  79. +#include <yaml-cpp/yaml.h>
  80. +#include <yaml-cpp/node/parse.h>
  81. #include <libcamera/camera.h>
  82. #include <libcamera/control_ids.h>
  83. @@ -39,14 +41,7 @@
  84. #define STF_MAX_CAMERAS 3
  85. -namespace libcamera {
  86. -
  87. -LOG_DEFINE_CATEGORY(STARFIVE)
  88. -
  89. -static constexpr unsigned int BUFFER_COUNT = 4;
  90. -static constexpr unsigned int MAX_STREAMS = 2;
  91. -static const Size OUTPUT_MIN_SIZE = { 8, 8 };
  92. -static const Size OUTPUT_MAX_SIZE = { 8192, 8192 };
  93. +#define PIPELINE_CONFIG_FILENAME "/etc/starfive/sensors_pipeline.yaml"
  94. namespace {
  95. @@ -66,14 +61,16 @@ typedef enum {
  96. typedef struct {
  97. std::string sensorEntityName_;
  98. std::string sensorFwImageName_;
  99. - SensorType sensorType_;
  100. + int sensorType_;
  101. } SensorConfig;
  102. -const std::vector<SensorConfig> sensorConfigs = {
  103. +const std::vector<SensorConfig> defaultSensorConfigs = {
  104. { "imx219 0-0010", "stf_isp0_fw_dump.bin", MIPICSI0_ISP0 },
  105. { "imx219 2-0010", "stf_isp0_fw_dump.bin", MIPICSI1_ISP1 },
  106. };
  107. +std::vector<SensorConfig> sensorConfigs;
  108. +
  109. typedef struct {
  110. std::string source;
  111. std::string link;
  112. @@ -139,6 +136,40 @@ const std::vector<PipelineConfigLink> pipelineConfigs[SENSORTYPE_MAX] = {
  113. mipicsi1raw1Config,
  114. };
  115. +} /* namespace */
  116. +
  117. +namespace YAML {
  118. + template<>
  119. + struct convert<SensorConfig> {
  120. + static Node encode(const SensorConfig& sensor) {
  121. + Node node;
  122. + node.push_back(sensor.sensorEntityName_);
  123. + node.push_back(sensor.sensorFwImageName_);
  124. + node.push_back(sensor.sensorType_);
  125. + return node;
  126. + }
  127. +
  128. + static bool decode(const Node& node, SensorConfig& sensor) {
  129. + if(node.size() != 3)
  130. + return false;
  131. +
  132. + sensor.sensorEntityName_ = node["sensorentity"].as<std::string>();
  133. + sensor.sensorFwImageName_ = node["ispfwimage"].as<std::string>();
  134. + sensor.sensorType_ = node["sensortype"].as<int>();
  135. + return true;
  136. + }
  137. + };
  138. +}
  139. +
  140. +namespace libcamera {
  141. +
  142. +LOG_DEFINE_CATEGORY(STARFIVE)
  143. +
  144. +static constexpr unsigned int BUFFER_COUNT = 4;
  145. +static constexpr unsigned int MAX_STREAMS = 2;
  146. +static const Size OUTPUT_MIN_SIZE = { 8, 8 };
  147. +static const Size OUTPUT_MAX_SIZE = { 8192, 8192 };
  148. +
  149. const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {
  150. { MEDIA_BUS_FMT_SBGGR10_1X10, formats::SBGGR12 },
  151. { MEDIA_BUS_FMT_SGBRG10_1X10, formats::SGBRG12 },
  152. @@ -146,8 +177,6 @@ const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {
  153. { MEDIA_BUS_FMT_SRGGB10_1X10, formats::SRGGB12 },
  154. };
  155. -} /* namespace */
  156. -
  157. class StarFiveCameraData : public Camera::Private
  158. {
  159. public:
  160. @@ -423,6 +452,7 @@ private:
  161. int enableLinks(std::vector<PipelineConfigLink> config);
  162. MediaDevice *starFiveMediaDev_;
  163. + int parserPipelineConfig(const char *filename);
  164. };
  165. StarFiveCameraConfiguration::StarFiveCameraConfiguration(StarFiveCameraData *data)
  166. @@ -1042,6 +1072,56 @@ int PipelineHandlerStarFive::enableLinks(std::vector<PipelineConfigLink> config)
  167. return ret;
  168. }
  169. +static void loaddefaultSensorConfig(void)
  170. +{
  171. + LOG(STARFIVE, Debug) << __func__;
  172. + sensorConfigs.clear();
  173. + for (SensorConfig it : defaultSensorConfigs)
  174. + sensorConfigs.push_back(it);
  175. +}
  176. +
  177. +static void printSensorConfig(void)
  178. +{
  179. + for (SensorConfig it : sensorConfigs)
  180. + LOG(STARFIVE, Debug)
  181. + << " sensorEntityName: " << it.sensorEntityName_
  182. + << ", ispLoadFW: " << it.sensorFwImageName_
  183. + << ", sensorType: " << it.sensorType_;
  184. +}
  185. +
  186. +int PipelineHandlerStarFive::parserPipelineConfig(const char *filename)
  187. +{
  188. + LOG(STARFIVE, Debug) << __func__;
  189. + try {
  190. + YAML::Node config = YAML::LoadFile(PIPELINE_CONFIG_FILENAME);
  191. +
  192. + if (config["sensors"]) {
  193. + std::vector<SensorConfig> sensors =
  194. + config["sensors"].as<std::vector<SensorConfig>>();
  195. + int found = 0;
  196. +
  197. + for (SensorConfig it : sensors) {
  198. + found = 0;
  199. + for (SensorConfig its : sensorConfigs) {
  200. + if (its.sensorEntityName_ == it.sensorEntityName_) {
  201. + found = 1;
  202. + break;
  203. + }
  204. + }
  205. + if (!found)
  206. + sensorConfigs.push_back(it);
  207. + }
  208. + }
  209. + } catch(std::exception const & e) {
  210. + LOG(STARFIVE, Debug) << PIPELINE_CONFIG_FILENAME
  211. + << " yaml file error, use default config!!!";
  212. + loaddefaultSensorConfig();
  213. + }
  214. +
  215. + printSensorConfig();
  216. + return 0;
  217. +}
  218. +
  219. bool PipelineHandlerStarFive::match(DeviceEnumerator *enumerator)
  220. {
  221. int numCameras = 0;
  222. @@ -1059,6 +1139,8 @@ bool PipelineHandlerStarFive::match(DeviceEnumerator *enumerator)
  223. if (starFiveMediaDev_->disableLinks())
  224. return false;
  225. + parserPipelineConfig(PIPELINE_CONFIG_FILENAME);
  226. +
  227. for (SensorConfig it : sensorConfigs) {
  228. MediaEntity *sensorEntity =
  229. starFiveMediaDev_->getEntityByName(it.sensorEntityName_);
  230. --
  231. 2.25.1