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:
@@ -18,15 +18,13 @@ set -e
|
|||||||
# call get_param section param
|
# call get_param section param
|
||||||
# spits out raw value
|
# spits out raw value
|
||||||
function get_param {
|
function get_param {
|
||||||
local cfg
|
local cfg section param
|
||||||
local section
|
|
||||||
local param
|
|
||||||
cfg="${WEBCAMD_CFG}"
|
cfg="${WEBCAMD_CFG}"
|
||||||
section="${1}"
|
section="${1}"
|
||||||
param="${2}"
|
param="${2}"
|
||||||
crudini --get "${cfg}" "${section}" "${param}" | \
|
crudini --get "${cfg}" "${section}" "${param}" | \
|
||||||
sed 's/\#.*//;s/[[:space:]]*$//'
|
sed 's/\#.*//;s/[[:space:]]*$//' || echo ""
|
||||||
} 2> /dev/null
|
}
|
||||||
|
|
||||||
# Check for existing file
|
# Check for existing file
|
||||||
# Exit with error if not exist
|
# Exit with error if not exist
|
||||||
@@ -39,11 +37,13 @@ function check_cfg {
|
|||||||
|
|
||||||
## Spits out all [cam <nameornumber>] configured sections
|
## Spits out all [cam <nameornumber>] configured sections
|
||||||
function configured_cams {
|
function configured_cams {
|
||||||
local cam_count cfg
|
local cams cfg
|
||||||
cfg="${WEBCAMD_CFG}"
|
cfg="${WEBCAMD_CFG}"
|
||||||
cams="$(crudini --existing=file --get "${cfg}" | \
|
for i in $(crudini --existing=file --get "${cfg}" | \
|
||||||
sed '/webcamd/d;s/cam//')"
|
sed '/webcamd/d;s/cam//'); do
|
||||||
echo "${cams}"
|
cams+=("${i}")
|
||||||
|
done
|
||||||
|
echo "${cams[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks [cam <nameornumber>] if all needed configuration sections are present
|
# Checks [cam <nameornumber>] if all needed configuration sections are present
|
||||||
@@ -53,7 +53,7 @@ function check_section {
|
|||||||
section="cam ${1}"
|
section="cam ${1}"
|
||||||
# Ignore missing custom flags
|
# Ignore missing custom flags
|
||||||
param="$(crudini --existing=param --get "${WEBCAMD_CFG}" "${section}" \
|
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"
|
must_exist="streamer port device resolution max_fps"
|
||||||
missing="$(echo "${param}" "${must_exist}" | \
|
missing="$(echo "${param}" "${must_exist}" | \
|
||||||
tr ' ' '\n' | sort | uniq -u)"
|
tr ' ' '\n' | sort | uniq -u)"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#### Init Stream library
|
#### v4l2 control library
|
||||||
|
|
||||||
#### webcamd - A webcam Service for multiple Cams and Stream Services.
|
#### webcamd - A webcam Service for multiple Cams and Stream Services.
|
||||||
####
|
####
|
||||||
@@ -10,7 +10,49 @@
|
|||||||
####
|
####
|
||||||
#### This File is distributed under GPLv3
|
#### This File is distributed under GPLv3
|
||||||
####
|
####
|
||||||
|
#### Description: Configure Cam with v4l2-ctl options
|
||||||
|
#### ex.: v4l2-ctl -c brightness=100
|
||||||
|
|
||||||
# Exit upon Errors
|
# Exit upon Errors
|
||||||
set -e
|
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
|
||||||
|
}
|
||||||
|
3
webcamd
3
webcamd
@@ -29,7 +29,7 @@ source "${BASE_CN_PATH}/libs/logging.sh"
|
|||||||
source "${BASE_CN_PATH}/libs/messages.sh"
|
source "${BASE_CN_PATH}/libs/messages.sh"
|
||||||
source "${BASE_CN_PATH}/libs/watchdog.sh"
|
source "${BASE_CN_PATH}/libs/watchdog.sh"
|
||||||
source "${BASE_CN_PATH}/libs/init_stream.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 {
|
function run_ustreamer {
|
||||||
local cam_section ustreamer_bin device port resolution fps custom
|
local cam_section ustreamer_bin device port resolution fps custom
|
||||||
@@ -138,6 +138,7 @@ done
|
|||||||
develop
|
develop
|
||||||
init_log_entry
|
init_log_entry
|
||||||
initial_check
|
initial_check
|
||||||
|
v4l2_control
|
||||||
construct_streamer
|
construct_streamer
|
||||||
|
|
||||||
## Loop and Watchdog
|
## Loop and Watchdog
|
||||||
|
Reference in New Issue
Block a user