diff --git a/libs/hwhandler.sh b/libs/hwhandler.sh index 9bf4f3b3..16026d2b 100755 --- a/libs/hwhandler.sh +++ b/libs/hwhandler.sh @@ -84,6 +84,23 @@ get_libcamera_path() { fi } +# Determine connected "legacy" device +function detect_legacy { + local avail + if [[ -f /proc/device-tree/model ]] && + grep -q "Raspberry" /proc/device-tree/model; then + avail="$(vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)" + else + avail="0" + fi + echo "${avail}" +} + +function dev_is_legacy { + v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \ + awk 'NR==2 {print $1}' +} + ## Determine if cam has H.264 Hardware encoder ## call detect_h264 ex.: detect_h264 foobar ## returns 1 = true / 0 = false ( numbers are strings! not int!) diff --git a/libs/logging.sh b/libs/logging.sh index 43a38cec..828cd7c6 100755 --- a/libs/logging.sh +++ b/libs/logging.sh @@ -90,7 +90,7 @@ function print_cfg { function print_cams { local total v4l v4l="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null | wc -l)" - total="$((v4l+($(detect_libcamera))))" + total="$((v4l+($(detect_libcamera))+($(detect_legacy))))" if [ "${total}" -eq 0 ]; then log_msg "ERROR: No usable Devices Found. Stopping $(basename "${0}")." exit 1 @@ -100,6 +100,15 @@ function print_cams { if [[ "$(detect_libcamera)" -ne 0 ]]; then log_msg "Detected 'libcamera' device -> $(get_libcamera_path)" fi + if [[ "$(detect_legacy)" -ne 0 ]]; then + raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \ + awk 'NR==2 {print $1}')" + log_msg "Detected 'Raspicam' Device -> ${raspicam}" + if [[ ! "${CROWSNEST_LOG_LEVEL}" = "quiet" ]]; then + list_cam_formats "${raspicam}" + list_cam_v4l2ctrls "${raspicam}" + fi + fi if [[ -d "/dev/v4l/by-id/" ]]; then detect_avail_cams fi diff --git a/libs/ustreamer.sh b/libs/ustreamer.sh index 000d38d3..3f588eec 100755 --- a/libs/ustreamer.sh +++ b/libs/ustreamer.sh @@ -23,6 +23,7 @@ run_mjpg() { for instance in ${cams} ; do run_ustreamer "${instance}" & done + blockyfix brokenfocus return } @@ -45,12 +46,17 @@ run_ustreamer() { start_param=( --host 127.0.0.1 -p "${pt}" ) fi - # Add device - start_param+=( -d "${dev}" --device-timeout=2 ) + #Raspicam Workaround + if [[ "${dev}" = "$(dev_is_legacy)" ]]; then + start_param+=( -m MJPEG --device-timeout=5 --buffers=3 ) + else + # Add device + start_param+=( -d "${dev}" --device-timeout=2 ) - # Use MJPEG Hardware encoder if possible - if [ "$(detect_mjpeg "${cam_sec}")" = "1" ]; then - start_param+=( -m MJPEG --encoder=HW ) + # Use MJPEG Hardware encoder if possible + if [ "$(detect_mjpeg "${cam_sec}")" = "1" ]; then + start_param+=( -m MJPEG --encoder=HW ) + fi fi # set max framerate diff --git a/libs/v4l2_control.sh b/libs/v4l2_control.sh index 15ddecb8..d7630219 100755 --- a/libs/v4l2_control.sh +++ b/libs/v4l2_control.sh @@ -136,3 +136,30 @@ function brokenfocus { main } + +# This function is to set bitrate on raspicams. +# If raspicams set to variable bitrate, they tend to show +# a "block-like" view after reboots +# To prevent that blockyfix should apply constant bitrate befor start of ustreamer +# See https://github.com/mainsail-crew/crowsnest/issues/33 +function blockyfix { + local dev v4l2ctl + + # call set_bitrate + function set_bitrate { + v4l2-ctl -d "${1}" -c video_bitrate_mode=1 2> /dev/null + v4l2-ctl -d "${1}" -c video_bitrate=15000000 2> /dev/null + } + + for cam in $(configured_cams); do + dev="$(get_param "cam ${cam}" device)" + v4l2ctl="$(get_param "cam ${cam}" v4l2ctl)" + if [ "${dev}" = "$(dev_is_legacy)" ]; then + if [ -z "${v4l2ctl}" ] || + [ "$(grep -c "video_bitrate" <<< "${v4l2ctl}")" == "0" ]; then + set_bitrate "${dev}" + blockyfix_msg_1 + fi + fi + done +}