libcamera: support Rectangle and Size types

Fixes: https://github.com/ayufan/camera-streamer/issues/28
Replaces: https://github.com/ayufan/camera-streamer/pull/30
This commit is contained in:
Kamil Trzcinski
2023-02-22 17:59:29 +01:00
parent d963fdd16d
commit aafd120af3
3 changed files with 70 additions and 26 deletions

View File

@ -258,7 +258,7 @@ int device_set_rotation(device_t *dev, bool vflip, bool hflip)
int device_set_option_string(device_t *dev, const char *key, const char *value)
{
if (!dev) {
return -1;
return 0;
}
return dev->hw->device_set_option(dev, key, value);

View File

@ -173,9 +173,43 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val
control_value.set<float>(atof(value));
break;
case libcamera::ControlTypeString:
case libcamera::ControlTypeRectangle:
static const char *RECTANGLE_PATTERNS[] = {
"(%d,%d)/%ux%u",
"%d,%d,%u,%u",
NULL
};
for (int i = 0; RECTANGLE_PATTERNS[i]; i++) {
libcamera::Rectangle rectangle;
if (4 == sscanf(value, RECTANGLE_PATTERNS[i],
&rectangle.x, &rectangle.y,
&rectangle.width, &rectangle.height)) {
control_value.set(rectangle);
break;
}
}
break;
case libcamera::ControlTypeSize:
static const char *SIZE_PATTERNS[] = {
"%ux%u",
"%u,%u",
NULL
};
for (int i = 0; SIZE_PATTERNS[i]; i++) {
libcamera::Size size;
if (2 == sscanf(value, SIZE_PATTERNS[i], &size.width, &size.height)) {
control_value.set(size);
break;
}
}
break;
case libcamera::ControlTypeString:
break;
}
@ -187,9 +221,11 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val
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;
return 1;
}
return 0;
error:
return -1;
}