Skip to content

Conversation

@arekm
Copy link
Contributor

@arekm arekm commented May 22, 2025

libcamera_parse_control_value() splits options by coma which makes sense for many options but it mishandles options like:
"AfWindows=(1152,1296)/2304x1296" or "ScalerCrop=(0,0)/4608x2592".

Example:
./camera-streamer --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(1152,1296)/2304x1296" 2>&1 |grep AfWindows device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = [ (0, 0)/0x0, (0, 0)/0x0 ]

It parsed option incorrectly end got wrong [ (0, 0)/0x0, (0, 0)/0x0 ] result.

Same for ScalerCrop:
./camera-streamer --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="ScalerCrop=(0,0)/4608x2592" 2>&1 |grep ScalerCrop device/libcamera/options.cc: CAMERA: Configuring option 'ScalerCrop' (0000001b, type=9) = [ (0, 0)/0x0, (0, 0)/0x0 ]

With fix options are parsed and interpreted correctly:

./camera-streamer --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(1152,1296)/2304x1296" 2>&1 |grep AfWindows device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = (1152, 1296)/2304x1296

so expected (1152, 1296)/2304x1296

./camera-streamer --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="ScalerCrop=(0,0)/4608x2592" 2>&1 |grep ScalerCrop device/libcamera/options.cc: CAMERA: Configuring option 'ScalerCrop' (0000001b, type=9) = (0, 0)/4608x2592

and also expected (0, 0)/4608x2592

Fixes #114

Also decode POST arguments, so if you set option like ScalerCrop fro web UI you will get it correctly applied.
For example set via web ui: ScalerCrop to (964,436)/3000x1920

With fix:
util/http/http.c: HTTP8080/5: Request 'POST' '/option' 'device=CAMERA&key=scalercrop&value=(964%2C436)%2F3000x1920' device/libcamera/options.cc: CAMERA: Configuring option 'ScalerCrop' (0000001b, type=9) = (964, 436)/3000x1920

Fixes #115

Also libcamera_parse_control_value needs to create Span (Array) of Rectangles
when original type is an Span (Array).

This change implements that.

Avoids assert:

$ ./camera-streamer --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(0,0)/500x500" --http-listen=0.0.0.0 [...] device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = (0, 0)/500x500 [... and when stream client connects...] camera-streamer: ../include/libcamera/controls.h:204: T libcamera::ControlValue::get() const [with T = libcamera::Span<const libcamera::Rectangle>; typename std::enable_if<(libcamera::details::is_span<U>::value || std::is_same<std::__cxx11::basic_ string<char>, typename std::remove_cv< <template-parameter-1-1> >::type>::value), std::nullptr_t>::type <anonymous> = nullptr]: AssertionisArray_' failed.
Aborted
`

Fixes #171

arekm added 3 commits May 30, 2025 16:43
libcamera_parse_control_value() splits options by coma which makes sense
for many options but it mishandles options like:
"AfWindows=(1152,1296)/2304x1296" or "ScalerCrop=(0,0)/4608x2592".

Example:
./camera-streamer  --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(1152,1296)/2304x1296" 2>&1 |grep AfWindows
device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = [ (0, 0)/0x0, (0, 0)/0x0 ]

It parsed option incorrectly end got [ (0, 0)/0x0, (0, 0)/0x0 ] result.

Same for ScalerCrop:
./camera-streamer  --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="ScalerCrop=(0,0)/4608x2592" 2>&1 |grep ScalerCrop
device/libcamera/options.cc: CAMERA: Configuring option 'ScalerCrop' (0000001b, type=9) = [ (0, 0)/0x0, (0, 0)/0x0 ]

With fix options are parsed and interpreted correctly:
./camera-streamer  --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(1152,1296)/2304x1296" 2>&1 |grep AfWindows
device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = (1152, 1296)/2304x1296

./camera-streamer  --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="ScalerCrop=(0,0)/4608x2592" 2>&1 |grep ScalerCrop
device/libcamera/options.cc: CAMERA: Configuring option 'ScalerCrop' (0000001b, type=9) = (0, 0)/4608x2592

Fixes #114
libcamera_parse_control_value needs to create Span (Array) of Rectangles
when original type is an Span (Array).

This change implements that.

Avoids assert:

$ ./camera-streamer  --camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a --camera-type=libcamera --camera-options="AfWindows=(0,0)/500x500" --http-listen=0.0.0.0
[...]
device/libcamera/options.cc: CAMERA: Configuring option 'AfWindows' (00000025, type=9) = (0, 0)/500x500
[... and when stream client connects...]
camera-streamer: ../include/libcamera/controls.h:204: T libcamera::ControlValue::get() const [with T = libcamera::Span<const libcamera::Rectangle>; typename std::enable_if<(libcamera::details::is_span<U>::value || std::is_same<std::__cxx11::basic_
string<char>, typename std::remove_cv< <template-parameter-1-1> >::type>::value), std::nullptr_t>::type <anonymous> = nullptr]: Assertion `isArray_' failed.
Aborted
@arekm arekm changed the title 1) Fix splitting options by coma. 2) Also decode POST arguments. 1) Fix splitting options by coma. 2) Also decode POST arguments. 3) Fix handling Array of Rectangles May 30, 2025
}

// Helper function to decode percent-encoded strings
char *url_decode(const char *str) {
Copy link
Owner

@ayufan ayufan Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arekm Would you mind opening separate PR with this change only? And put opening brace on a new line.

@arekm arekm closed this by deleting the head repository Jun 8, 2025
@arekm
Copy link
Contributor Author

arekm commented Jun 8, 2025

For reference:
#175
#174
#172

@arekm arekm mentioned this pull request Jun 9, 2025
ayufan added a commit that referenced this pull request Jul 2, 2025
This does that by trying to parse value,
and then advancing pointer. It checks if the
string ends or is split by comma.

With collaboration from @arekm. Take a look at:

- #170
- #172
- #176
ayufan added a commit that referenced this pull request Jul 2, 2025
This does that by trying to parse value,
and then advancing pointer. It checks if the
string ends or is split by comma.

With collaboration from @arekm. Take a look at:

- #170
- #172
- #176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants