Add Feature V4L2 Control

* This feature allows you to setup v4l2-ctl parameters before stream starts.
* Modified webcamd accordingly.
* Modified libs/configparser.sh.
* Changed functions get_param configured_cams and check_section

Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
Stephan Wendel
2021-12-11 20:19:10 +01:00
parent 2a2bff5b31
commit 351703cc60
3 changed files with 55 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
#### Init Stream library
#### v4l2 control library
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
@@ -10,7 +10,49 @@
####
#### This File is distributed under GPLv3
####
#### Description: Configure Cam with v4l2-ctl options
#### ex.: v4l2-ctl -c brightness=100
# Exit upon Errors
set -e
function v4l2_control {
log_msg "V4L2 Control:"
function main {
local device v4l2ctl valueless opt_avail
for cam in $(configured_cams); do
# get device from cam section
device="$(get_param "cam ${cam}" device)"
# get v4l2ctl parameters
v4l2ctl="$(get_param "cam ${cam}" v4l2ctl)"
# if not empty do
if [ -n "${v4l2ctl}" ]; then
# Write configured options to Log
log_msg "Device: [cam $cam]"
log_msg "Options: ${v4l2ctl}"
# Split options to array
IFS=',' read -a opt < <(echo "${v4l2ctl}"); unset IFS
# loop through options
for param in "${opt[@]}"; do
# parameter available for device
# needs || true to prevent script to exit
valueless="$(echo "${param}" | cut -d "=" -f1)"
opt_avail="$(v4l2-ctl -d ${device} -L | \
grep -c ${valueless} || true)"
if [ "$opt_avail" -eq "0" ]; then
log_msg "Parameter '${param}' not available for '${device}'. Skipped."
else
v4l2-ctl -d "${device}" -c "${param}" 2> /dev/null
fi
done
else
log_msg "No parameters set for [cam ${cam}]. Skipped."
fi
done
}
### MAIN
main
}