Allow to configure controls
This commit is contained in:
@@ -38,7 +38,6 @@ void libcamera_device_close(device_t *dev)
|
||||
{
|
||||
if (dev->libcamera) {
|
||||
if (dev->libcamera->camera) {
|
||||
dev->libcamera->camera->stop();
|
||||
dev->libcamera->camera->release();
|
||||
}
|
||||
|
||||
@@ -47,23 +46,73 @@ void libcamera_device_close(device_t *dev)
|
||||
}
|
||||
}
|
||||
|
||||
int libcamera_device_set_decoder_start(device_t *dev, bool do_on)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int libcamera_device_video_force_key(device_t *dev)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int libcamera_device_set_fps(device_t *dev, int desired_fps)
|
||||
{
|
||||
int64_t frame_time = 1000000 / desired_fps;
|
||||
dev->libcamera->controls.set(libcamera::controls::FrameDurationLimits, { frame_time, frame_time });
|
||||
return -1;
|
||||
}
|
||||
|
||||
int libcamera_device_set_option(device_t *dev, const char *key, const char *value)
|
||||
std::string libcamera_device_option_normalize(std::string key)
|
||||
{
|
||||
key.resize(device_option_normalize_name(key.data(), key.data()));
|
||||
return key;
|
||||
}
|
||||
|
||||
int libcamera_device_set_option(device_t *dev, const char *keyp, const char *value)
|
||||
{
|
||||
auto key = libcamera_device_option_normalize(keyp);
|
||||
|
||||
for (auto const &control : dev->libcamera->camera->controls()) {
|
||||
if (!control.first)
|
||||
continue;
|
||||
|
||||
auto control_id = control.first;
|
||||
auto control_key = libcamera_device_option_normalize(control_id->name());
|
||||
if (key != control_key)
|
||||
continue;
|
||||
|
||||
libcamera::ControlValue control_value;
|
||||
|
||||
switch (control_id->type()) {
|
||||
case libcamera::ControlTypeBool:
|
||||
control_value.set<bool>(atoi(value));
|
||||
break;
|
||||
|
||||
case libcamera::ControlTypeByte:
|
||||
control_value.set<unsigned char>(atoi(value));
|
||||
break;
|
||||
|
||||
case libcamera::ControlTypeInteger32:
|
||||
control_value.set<int32_t>(atoi(value));
|
||||
break;
|
||||
|
||||
case libcamera::ControlTypeInteger64:
|
||||
control_value.set<int64_t>(atoi(value));
|
||||
break;
|
||||
|
||||
case libcamera::ControlTypeFloat:
|
||||
control_value.set<float>(atof(value));
|
||||
break;
|
||||
|
||||
case libcamera::ControlTypeString:
|
||||
case libcamera::ControlTypeRectangle:
|
||||
case libcamera::ControlTypeSize:
|
||||
break;
|
||||
}
|
||||
|
||||
if (control_value.isNone()) {
|
||||
E_LOG_ERROR(dev, "The `%s` type `%d` is not supported.", control_key.c_str(), control_id->type());
|
||||
}
|
||||
|
||||
E_LOG_INFO(dev, "Configuring option %s (%08x, type=%d) = %s",
|
||||
control_key.c_str(), control_id->id(), control_id->type(),
|
||||
control_value.toString().c_str());
|
||||
dev->libcamera->controls.set(control_id->id(), control_value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
#endif // USE_LIBCAMERA
|
||||
|
Reference in New Issue
Block a user