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

@@ -18,15 +18,13 @@ set -e
# call get_param section param
# spits out raw value
function get_param {
local cfg
local section
local param
local cfg section param
cfg="${WEBCAMD_CFG}"
section="${1}"
param="${2}"
crudini --get "${cfg}" "${section}" "${param}" | \
sed 's/\#.*//;s/[[:space:]]*$//'
} 2> /dev/null
sed 's/\#.*//;s/[[:space:]]*$//' || echo ""
}
# Check for existing file
# Exit with error if not exist
@@ -39,11 +37,13 @@ function check_cfg {
## Spits out all [cam <nameornumber>] configured sections
function configured_cams {
local cam_count cfg
local cams cfg
cfg="${WEBCAMD_CFG}"
cams="$(crudini --existing=file --get "${cfg}" | \
sed '/webcamd/d;s/cam//')"
echo "${cams}"
for i in $(crudini --existing=file --get "${cfg}" | \
sed '/webcamd/d;s/cam//'); do
cams+=("${i}")
done
echo "${cams[@]}"
}
# Checks [cam <nameornumber>] if all needed configuration sections are present
@@ -53,7 +53,7 @@ function check_section {
section="cam ${1}"
# Ignore missing custom flags
param="$(crudini --existing=param --get "${WEBCAMD_CFG}" "${section}" \
2> /dev/null | sed '/custom_flags/d')"
2> /dev/null | sed '/custom_flags/d;/v4l2ctl/d')"
must_exist="streamer port device resolution max_fps"
missing="$(echo "${param}" "${must_exist}" | \
tr ' ' '\n' | sort | uniq -u)"

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
}

View File

@@ -29,7 +29,7 @@ source "${BASE_CN_PATH}/libs/logging.sh"
source "${BASE_CN_PATH}/libs/messages.sh"
source "${BASE_CN_PATH}/libs/watchdog.sh"
source "${BASE_CN_PATH}/libs/init_stream.sh"
# source "${BASE_CN_PATH}/libs/v4l2_control.sh"
source "${BASE_CN_PATH}/libs/v4l2_control.sh"
function run_ustreamer {
local cam_section ustreamer_bin device port resolution fps custom
@@ -138,6 +138,7 @@ done
develop
init_log_entry
initial_check
v4l2_control
construct_streamer
## Loop and Watchdog