@@ -72,6 +72,13 @@ CameraSession::CameraSession(CameraManager *cm,
return;
}
+ /* Apply a sensor configuration is requested. */
+ if (SensorKeyValueParser::updateConfiguration(config.get(),
+ options_[OptSensorFmt])) {
+ std::cerr << "Failed to apply sensor configuration" << std::endl;
+ return;
+ }
+
bool strictFormats = options_.isSet(OptStrictFormats);
#ifdef HAVE_KMS
@@ -110,6 +110,7 @@ void CamApp::quit()
int CamApp::parseOptions(int argc, char *argv[])
{
StreamKeyValueParser streamKeyValue;
+ SensorKeyValueParser sensorKeyValue;
OptionsParser parser;
parser.addOption(OptCamera, OptionString,
@@ -171,6 +172,9 @@ int CamApp::parseOptions(int argc, char *argv[])
"Load a capture session configuration script from a file",
"script", ArgumentRequired, "script", false,
OptCamera);
+ parser.addOption(OptSensorFmt, &sensorKeyValue,
+ "Apply a format to the sensor", "sensor_format", true,
+ OptCamera);
options_ = parser.parse(argc, argv);
if (!options_.valid())
@@ -19,6 +19,7 @@ enum {
OptMonitor = 'm',
OptSDL = 'S',
OptStream = 's',
+ OptSensorFmt = 'f',
OptListControls = 256,
OptStrictFormats = 257,
OptMetadata = 258,
@@ -119,3 +119,45 @@ std::optional<libcamera::StreamRole> StreamKeyValueParser::parseRole(const KeyVa
return {};
}
+
+SensorKeyValueParser::SensorKeyValueParser()
+{
+ addOption("bitDepth", OptionInteger, "Sensor format bit depth",
+ ArgumentRequired);
+ addOption("width", OptionInteger, "Sensor frame width in pixels",
+ ArgumentRequired);
+ addOption("height", OptionInteger, "Sensor frame height in pixels",
+ ArgumentRequired);
+}
+
+int SensorKeyValueParser::updateConfiguration(CameraConfiguration *config,
+ const OptionValue &values)
+{
+ if (!config) {
+ std::cerr << "No configuration provided" << std::endl;
+ return -EINVAL;
+ }
+
+ /* If no configuration values nothing to do. */
+ if (values.empty())
+ return 0;
+
+ const std::vector<OptionValue> &streamParameters = values.toArray();
+ SensorConfiguration sensorConfig;
+
+ for (auto const &value : streamParameters) {
+ KeyValueParser::Options opts = value.toKeyValues();
+
+ if (opts.isSet("width") && opts.isSet("height")) {
+ sensorConfig.outputSize.width = opts["width"];
+ sensorConfig.outputSize.height = opts["height"];
+ }
+
+ if (opts.isSet("bitDepth"))
+ sensorConfig.bitDepth = opts["bitDepth"];
+ }
+
+ config->sensorConfig = sensorConfig;
+
+ return 0;
+}
@@ -27,3 +27,11 @@ public:
private:
static std::optional<libcamera::StreamRole> parseRole(const KeyValueParser::Options &options);
};
+
+class SensorKeyValueParser : public KeyValueParser
+{
+public:
+ SensorKeyValueParser();
+ static int updateConfiguration(libcamera::CameraConfiguration *config,
+ const OptionValue &values);
+};
Add a '-f|--sensor_format' option to cam to allow forcing a sensor configuration from the command line. As an example: cam -c1 -C -S --stream pixelformat=YUYV -f width=3840,height=2160,bitDepth=10 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> --- src/apps/cam/camera_session.cpp | 7 +++++ src/apps/cam/main.cpp | 4 +++ src/apps/cam/main.h | 1 + src/apps/common/stream_options.cpp | 42 ++++++++++++++++++++++++++++++ src/apps/common/stream_options.h | 8 ++++++ 5 files changed, 62 insertions(+)