From c4a0ea3a8bbcaf80d48f40531fd451c3df0f6eeb Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 18 Feb 2017 20:59:30 +0200 Subject: [PATCH] removed various motioneye-specific files --- board/common/cleanups.sh | 2 +- board/common/mkimage.sh | 5 +- board/common/overlay/etc/fstab | 2 - board/common/overlay/etc/init.d/S61proftpd | 45 - board/common/overlay/etc/init.d/S62smb | 59 - board/common/overlay/etc/init.d/S85motioneye | 149 --- .../overlay/etc/modprobe.d/modprobe.conf | 4 - board/common/overlay/etc/motioneye.conf | 24 - board/common/overlay/etc/os.conf | 4 +- board/common/overlay/etc/proftpd.conf | 25 - board/common/overlay/etc/samba/smb.conf | 31 - .../usr/share/post-upgrade/20151128.sh | 7 - board/common/skeleton/home/ftp/.empty | 0 board/common/skeleton/home/ftp/sdcard/.empty | 0 board/common/skeleton/home/ftp/storage/.empty | 0 board/odroidc1/overlay/etc/os.conf | 5 +- board/odroidc2/overlay/etc/os.conf | 5 +- .../raspberrypi/motioneye-modules/boardctl.py | 310 ----- .../motioneye-modules/streameyectl.py | 1172 ----------------- .../overlay/etc/init.d/S84streameye | 51 - board/raspberrypi/overlay/etc/modules | 3 - .../raspberrypi/overlay/usr/bin/streameye.sh | 93 -- .../motioneye-modules/boardctl.py | 290 ---- .../motioneye-modules/streameyectl.py | 1172 ----------------- .../overlay/etc/init.d/S84streameye | 51 - board/raspberrypi2/overlay/etc/modules | 3 - .../raspberrypi2/overlay/usr/bin/streameye.sh | 93 -- .../motioneye-modules/boardctl.py | 238 ---- .../motioneye-modules/streameyectl.py | 1172 ----------------- .../overlay/etc/init.d/S84streameye | 51 - board/raspberrypi3/overlay/etc/modules | 3 - .../raspberrypi3/overlay/usr/bin/streameye.sh | 93 -- 32 files changed, 13 insertions(+), 5149 deletions(-) delete mode 100755 board/common/overlay/etc/init.d/S61proftpd delete mode 100755 board/common/overlay/etc/init.d/S62smb delete mode 100755 board/common/overlay/etc/init.d/S85motioneye delete mode 100644 board/common/overlay/etc/motioneye.conf delete mode 100644 board/common/overlay/etc/proftpd.conf delete mode 100644 board/common/overlay/etc/samba/smb.conf delete mode 100755 board/common/overlay/usr/share/post-upgrade/20151128.sh delete mode 100644 board/common/skeleton/home/ftp/.empty delete mode 100644 board/common/skeleton/home/ftp/sdcard/.empty delete mode 100644 board/common/skeleton/home/ftp/storage/.empty delete mode 100644 board/raspberrypi/motioneye-modules/boardctl.py delete mode 100644 board/raspberrypi/motioneye-modules/streameyectl.py delete mode 100755 board/raspberrypi/overlay/etc/init.d/S84streameye delete mode 100644 board/raspberrypi/overlay/etc/modules delete mode 100755 board/raspberrypi/overlay/usr/bin/streameye.sh delete mode 100644 board/raspberrypi2/motioneye-modules/boardctl.py delete mode 100644 board/raspberrypi2/motioneye-modules/streameyectl.py delete mode 100755 board/raspberrypi2/overlay/etc/init.d/S84streameye delete mode 100644 board/raspberrypi2/overlay/etc/modules delete mode 100755 board/raspberrypi2/overlay/usr/bin/streameye.sh delete mode 100644 board/raspberrypi3/motioneye-modules/boardctl.py delete mode 100644 board/raspberrypi3/motioneye-modules/streameyectl.py delete mode 100755 board/raspberrypi3/overlay/etc/init.d/S84streameye delete mode 100644 board/raspberrypi3/overlay/etc/modules delete mode 100755 board/raspberrypi3/overlay/usr/bin/streameye.sh diff --git a/board/common/cleanups.sh b/board/common/cleanups.sh index c123f662e1..019b964485 100755 --- a/board/common/cleanups.sh +++ b/board/common/cleanups.sh @@ -176,7 +176,7 @@ rm -f $TARGET/usr/share/perl5 rm -rf $TARGET/usr/lib/python2.7/site-packages/samba/ rm -rf $TARGET/usr/lib/python2.7/ensurepip/ -# startup scripts +# buildroot default startup scripts rm -f $TARGET/etc/init.d/S01logging rm -f $TARGET/etc/init.d/S10udev rm -f $TARGET/etc/init.d/S15watchdog diff --git a/board/common/mkimage.sh b/board/common/mkimage.sh index a03fe9e77b..d9ef3cffa5 100755 --- a/board/common/mkimage.sh +++ b/board/common/mkimage.sh @@ -34,6 +34,7 @@ ROOT_IMG=$IMG_DIR/root.img ROOT_SIZE="180" # MB DISK_SIZE="220" # MB +OS_NAME=$(source $IMG_DIR/../../../board/common/overlay/etc/version && echo $os_short_name) # boot filesystem msg "creating boot loop device" @@ -163,8 +164,8 @@ msg "destroying root loop device" losetup -d $loop_dev sync -mv $DISK_IMG $(dirname $DISK_IMG)/motioneyeos-$BOARD.img -DISK_IMG=$(dirname $DISK_IMG)/motioneyeos-$BOARD.img +mv $DISK_IMG $(dirname $DISK_IMG)/$OS_NAME-$BOARD.img +DISK_IMG=$(dirname $DISK_IMG)/$OS_NAME-$BOARD.img msg "$(realpath "$DISK_IMG") is ready" diff --git a/board/common/overlay/etc/fstab b/board/common/overlay/etc/fstab index a138aac079..0d7dc25122 100644 --- a/board/common/overlay/etc/fstab +++ b/board/common/overlay/etc/fstab @@ -6,6 +6,4 @@ tmpfs /tmp tmpfs mode=1777 0 0 sysfs /sys sysfs defaults 0 0 /dev/mmcblk0p1 /boot vfat ro,defaults 0 0 /dev/mmcblk0p3 /data ext4 defaults,noatime 0 0 -/data/output /home/ftp/sdcard rbind rbind 0 0 -/data/media /home/ftp/storage rbind rbind 0 0 diff --git a/board/common/overlay/etc/init.d/S61proftpd b/board/common/overlay/etc/init.d/S61proftpd deleted file mode 100755 index 92ad723780..0000000000 --- a/board/common/overlay/etc/init.d/S61proftpd +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -test -f /etc/proftpd.conf || exit 0 - -test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf - -test "$os_networkless" == "true" && exit 0 - -start() { - msg_begin "Starting proftpd" - mkdir -p /var/run/proftpd - touch /var/log/wtmp - /usr/sbin/proftpd &>/dev/null - test $? == 0 && msg_done || msg_fail -} - -stop() { - msg_begin "Stopping proftpd" - killall proftpd &>/dev/null - test $? == 0 && msg_done || msg_fail -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 - ;; -esac - -exit 0 - diff --git a/board/common/overlay/etc/init.d/S62smb b/board/common/overlay/etc/init.d/S62smb deleted file mode 100755 index f7d3ebd102..0000000000 --- a/board/common/overlay/etc/init.d/S62smb +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -test -f /etc/samba/smb.conf || exit 0 - -test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf - -test "$os_networkless" == "true" && exit 0 - -start() { - msg_begin "Setting smb admin password" - - mkdir -p /var/log/samba - mkdir -p /var/lib/samba/private - - password=$(/etc/init.d/adminpw) - echo -e "$password\n$password\n" | /usr/bin/smbpasswd -a admin -s > /dev/null - test $? == 0 && msg_done || msg_fail - - msg_begin "Starting smbd" - smbd -D - test $? == 0 && msg_done || msg_fail - - msg_begin "Starting nmbd" - nmbd -D - test $? == 0 && msg_done || msg_fail -} - -stop() { - msg_begin "Stopping smbd" - killall smbd &>/dev/null - test $? == 0 && msg_done || msg_fail - - msg_begin "Stopping nmbd" - killall nmbd &>/dev/null - test $? == 0 && msg_done || msg_fail -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/common/overlay/etc/init.d/S85motioneye b/board/common/overlay/etc/init.d/S85motioneye deleted file mode 100755 index 34f758e294..0000000000 --- a/board/common/overlay/etc/init.d/S85motioneye +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash - -sys_conf="/etc/motioneye.conf" -boot_conf="/boot/motioneye.conf" -conf="/data/etc/motioneye.conf" -motion_conf="/data/etc/motion.conf" -watch_conf="/data/etc/watch.conf" - -meyewatch_timeout=120 -meyewatch_disable="false" -dev_v4l_by_id="/dev/v4l/by-id/" -media_dir="/data/output" - -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then - cp $boor_conf $conf - elif [ -f $sys_conf ]; then - cp $sys_conf $conf - fi -fi - -test -f "$conf" || exit 0 - -test -r $watch_conf && source $watch_conf - -test -n "$os_version" || source /etc/init.d/base - -opts=$(cat "$conf" | while read line; do echo "--$line"; done) -port=$(echo "$opts" | grep -oE 'port [[:digit:]]+' | cut -d ' ' -f 2) - -responsive() { - wget --method=HEAD -q -t 1 -T 2 -O - http://127.0.0.1:$port &>/dev/null && return 0 || return 1 -} - -watch() { - count=0 - while true; do - sleep 5 - if responsive; then - count=0 - else - if [ $count -lt $meyewatch_timeout ]; then - count=$(($count + 5)) - else - logger -t motioneye -s "not responding for $meyewatch_timeout seconds, rebooting" - reboot - fi - fi - done -} - -find_persistent_device() { - device=$1 - - if ! [ -d $dev_v4l_by_id ]; then - echo $device - return - fi - - for p in $dev_v4l_by_id/*; do - if [ $(realpath "$p") == $device ]; then - echo $p | sed 's#//*#/#g' - return - fi - done - - echo $device -} - -start() { - msg_begin "Starting motioneye" - - mkdir -p $media_dir - meyectl startserver -b -c $conf -l - - count=0 - while true; do - sleep 1 - - if responsive; then - break - fi - - if [ $count -gt $meyewatch_timeout ]; then - msg_fail - test "$meyewatch_disable" == "false" && reboot - return 1 - fi - - count=$(($count + 1)) - done - - # add connected camera(s) with default settings - if responsive && ! [ -f $motion_conf ]; then - count=$(ls /dev/video* 2>/dev/null | wc -l) - index=1 - for device in $(ls /dev/video* 2>/dev/null); do - if [ "$count" -gt "1" ]; then - output_dir="/data/output/camera$index/" - else - output_dir="/data/output/" - fi - loc="/config/add/?_username=admin" - device=$(find_persistent_device $device) - body="{\"path\": \"$device\", \"proto\": \"v4l2\"}" - signature=$(echo -n "POST:$loc:$body:" | sha1sum | cut -d ' ' -f 1) - - curl -s -m 60 --data "$body" "http://127.0.0.1:$port$loc&_signature=$signature" > /dev/null - index=$(($index + 1)) - done - - sync - fi - - if [ "$meyewatch_disable" == "false" ]; then - watch & - fi - - msg_done -} - -stop() { - msg_begin "Stopping motioneye" - meyectl stopserver -c $conf &>/dev/null - test $? == 0 && msg_done || msg_fail - ps | grep motioneye | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/common/overlay/etc/modprobe.d/modprobe.conf b/board/common/overlay/etc/modprobe.d/modprobe.conf index ad96e42ffa..fd739a3b6e 100644 --- a/board/common/overlay/etc/modprobe.d/modprobe.conf +++ b/board/common/overlay/etc/modprobe.d/modprobe.conf @@ -5,7 +5,3 @@ options rndis_wlan power_save=0 options b43 hwpctl=0 options ath6kl_core suspend_mode=1 options brcmfmac roamoff=1 - -# media -options stk1160 keep_buffers=1 - diff --git a/board/common/overlay/etc/motioneye.conf b/board/common/overlay/etc/motioneye.conf deleted file mode 100644 index 774921b3c1..0000000000 --- a/board/common/overlay/etc/motioneye.conf +++ /dev/null @@ -1,24 +0,0 @@ -conf_path /data/etc -run_path /tmp -log_path /var/log -media_path /data/output -motion_binary /usr/bin/motion -log_level info -listen 0.0.0.0 -port 80 -mount_check_interval 300 -motion_check_interval 10 -cleanup_interval 43200 -remote_request_timeout 10 -mjpg_client_timeout 10 -mjpg_client_idle_timeout 10 -smb_shares true -smb_mount_root /data/media -wpa_supplicant_conf /data/etc/wpa_supplicant.conf -local_time_file /data/etc/localtime -enable_reboot true -enable_update true -smtp_timeout 60 -zip_timeout 500 -add_remove_cameras true - diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index 17dff80601..96fff5eb4a 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -6,9 +6,7 @@ os_wlan="wlan0" os_ppp="ppp0" os_networkless="false" os_country="GB" - os_firmware_method="github" -os_firmware_repo="ccrisan/motioneyeos" +os_firmware_repo="ccrisan/thingos" os_firmware_username="" os_firmware_password="" - diff --git a/board/common/overlay/etc/proftpd.conf b/board/common/overlay/etc/proftpd.conf deleted file mode 100644 index 054e36c9e1..0000000000 --- a/board/common/overlay/etc/proftpd.conf +++ /dev/null @@ -1,25 +0,0 @@ -ServerIdent off -ServerType standalone -DefaultServer on -Port 21 -UseIPv6 off -Umask 022 -MaxInstances 4 -User ftp -Group nogroup -DefaultRoot /home/ftp -AllowOverwrite on -RequireValidShell off -UseFtpUsers off -RootLogin on - - - DenyAll - - - - DenyAll - - -Include /data/etc/proftpd*.conf - diff --git a/board/common/overlay/etc/samba/smb.conf b/board/common/overlay/etc/samba/smb.conf deleted file mode 100644 index 652b03952e..0000000000 --- a/board/common/overlay/etc/samba/smb.conf +++ /dev/null @@ -1,31 +0,0 @@ -[global] - workgroup = MOTIONEYE - server string = motionEye - security = user - map to guest = bad user - encrypt passwords = yes - private dir = /var/lib/samba/private - public = no - writable = no - include = /data/etc/smb.conf - load printers = no - printing = bsd - printcap name = /dev/null - disable spoolss = yes - bind interfaces only = yes - interfaces = eth0 wlan0 - log level = 0 - syslog = 0 - preferred master = no - domain master = no - local master = no - os level = 0 - -[sdcard] - comment = SD Card Output Directory - path = /data/output - -[storage] - comment = Attached Storage Devices - path = /data/media - diff --git a/board/common/overlay/usr/share/post-upgrade/20151128.sh b/board/common/overlay/usr/share/post-upgrade/20151128.sh deleted file mode 100755 index ed3212612c..0000000000 --- a/board/common/overlay/usr/share/post-upgrade/20151128.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# option "thumbnailer_interval" has been removed from motionEye config - -grep -v 'thumbnailer_interval' /data/etc/motioneye.conf > /tmp/motioneye.conf -mv /tmp/motioneye.conf /data/etc/ - diff --git a/board/common/skeleton/home/ftp/.empty b/board/common/skeleton/home/ftp/.empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/board/common/skeleton/home/ftp/sdcard/.empty b/board/common/skeleton/home/ftp/sdcard/.empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/board/common/skeleton/home/ftp/storage/.empty b/board/common/skeleton/home/ftp/storage/.empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/board/odroidc1/overlay/etc/os.conf b/board/odroidc1/overlay/etc/os.conf index 674d736a30..e12b10ec7d 100644 --- a/board/odroidc1/overlay/etc/os.conf +++ b/board/odroidc1/overlay/etc/os.conf @@ -5,4 +5,7 @@ os_eth="eth0" os_wlan="wlan0" os_ppp="ppp0" os_networkless="false" - +os_firmware_method="github" +os_firmware_repo="ccrisan/thingos" +os_firmware_username="" +os_firmware_password="" diff --git a/board/odroidc2/overlay/etc/os.conf b/board/odroidc2/overlay/etc/os.conf index 674d736a30..e12b10ec7d 100644 --- a/board/odroidc2/overlay/etc/os.conf +++ b/board/odroidc2/overlay/etc/os.conf @@ -5,4 +5,7 @@ os_eth="eth0" os_wlan="wlan0" os_ppp="ppp0" os_networkless="false" - +os_firmware_method="github" +os_firmware_repo="ccrisan/thingos" +os_firmware_username="" +os_firmware_password="" diff --git a/board/raspberrypi/motioneye-modules/boardctl.py b/board/raspberrypi/motioneye-modules/boardctl.py deleted file mode 100644 index 289deb93a4..0000000000 --- a/board/raspberrypi/motioneye-modules/boardctl.py +++ /dev/null @@ -1,310 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import logging -import os.path -import subprocess - -from config import additional_config - -import streameyectl - - -CONFIG_TXT = '/boot/config.txt' -MONITOR = '/data/etc/monitor_1' - -MONITOR_SCRIPT = '''#!/bin/bash - -net_tmp=/tmp/netspeed.tmp -temp=$(($(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)) -load=$(cat /proc/loadavg | cut -d ' ' -f 2) -recv=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 3 | tail -n +3 | awk '{s+=$1} END {print s}') -send=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 11 | tail -n +3 | awk '{s+=$1} END {print s}') -total=$(($recv + $send)) - -if [ -e $net_tmp ]; then - prev_total=$(cat $net_tmp) - speed=$(($total - $prev_total)) -else - speed=0 -fi - -echo $total > $net_tmp -speed=$(($speed / 1024)) - -echo -n "$temp°|$load|${speed}kB/s" -''' - -OVERCLOCK = { - 700: '700|250|400|0', - 800: '800|250|400|0', - 900: '900|250|450|0', - 950: '950|250|450|0', - 1000: '1000|500|600|6', - 1001: '1001|300|450|6' -} - -def _is_pi_zero(): - try: - subprocess.check_call('grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]09[0-9a-fA-F]$" /proc/cpuinfo', shell=True) - return True - - except: - return False - - -def _get_board_settings(): - gpu_mem = 128 - camera_led = True - if _is_pi_zero(): - arm_freq = 1001 - - else: - arm_freq = 700 - - if os.path.exists(CONFIG_TXT): - logging.debug('reading board settings from %s' % CONFIG_TXT) - - with open(CONFIG_TXT) as f: - for line in f: - line = line.strip() - if not line or line.startswith('#'): - continue - - parts = line.split('=', 1) - if len(parts) != 2: - continue - - name, value = parts - name = name.strip() - value = value.strip() - - if name.startswith('gpu_mem'): - gpu_mem = int(value) - - elif name == 'arm_freq': - arm_freq = int(value) - - elif name == 'disable_camera_led': - camera_led = value == '0' - - overclock = OVERCLOCK.get(arm_freq, '700|250|400|0') - - s = { - 'gpuMem': gpu_mem, - 'overclock': overclock, - 'cameraLed': camera_led - } - - logging.debug('board settings: gpu_mem=%(gpuMem)s, overclock=%(overclock)s, camera_led=%(cameraLed)s' % s) - - return s - - -def _set_board_settings(s): - s.setdefault('gpuMem', 128) - s.setdefault('overclock', '700|250|400|0') - s.setdefault('cameraLed', True) - - old_settings = _get_board_settings() - if s == old_settings: - return # nothing has changed - - seen = set() - - logging.debug('writing board settings to %s: ' % CONFIG_TXT + - 'gpu_mem=%(gpuMem)s, overclock=%(overclock)s, camera_led=%(cameraLed)s' % s) - - arm_freq, gpu_freq, sdram_freq, over_voltage = s['overclock'].split('|') - - lines = [] - if os.path.exists(CONFIG_TXT): - with open(CONFIG_TXT) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - line = line.strip('#') - - try: - name, _ = line.split('=', 1) - name = name.strip() - - except: - continue - - seen.add(name) - - if name.startswith('gpu_mem'): - lines[i] = '%s=%s' % (name, s['gpuMem']) - - elif name == 'arm_freq': - lines[i] = 'arm_freq=%s' % arm_freq - - elif name in ['gpu_freq', 'core_freq']: - lines[i] = '%s=%s' % (name, gpu_freq) - - elif name == 'sdram_freq': - lines[i] = 'sdram_freq=%s' % sdram_freq - - elif name == 'over_voltage': - lines[i] = 'over_voltage=%s' % over_voltage - - elif name == 'disable_camera_led': - lines[i] = 'disable_camera_led=%s' % ['1', '0'][s['cameraLed']] - - if 'gpu_mem' not in seen: - lines.append('gpu_mem=%s' % s['gpuMem']) - - if 'gpu_mem_256' not in seen: - lines.append('gpu_mem_256=%s' % s['gpuMem']) - - if 'gpu_mem_512' not in seen: - lines.append('gpu_mem_512=%s' % s['gpuMem']) - - if 'arm_freq' not in seen: - lines.append('arm_freq=%s' % arm_freq) - - if 'gpu_freq' not in seen: - lines.append('gpu_freq=%s' % gpu_freq) - - if 'sdram_freq' not in seen: - lines.append('sdram_freq=%s' % sdram_freq) - - if 'over_voltage' not in seen: - lines.append('over_voltage=%s' % over_voltage) - - if 'disable_camera_led' not in seen: - lines.append('disable_camera_led=%s' % ['1', '0'][s['cameraLed']]) - - logging.debug('remounting /boot read-write') - if os.system('mount -o remount,rw /boot'): - logging.error('failed to remount /boot read-write') - - with open(CONFIG_TXT, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_sys_mon(): - return os.access(MONITOR, os.X_OK) - - -def _set_sys_mon(sys_mon): - if sys_mon: - if os.access(MONITOR, os.X_OK): - pass - - else: - if os.path.exists(MONITOR): - os.system('chmod +x %s' % MONITOR) - - else: - with open(MONITOR, 'w') as f: - f.write(MONITOR_SCRIPT) - - os.system('chmod +x %s' % MONITOR) - - else: - if os.access(MONITOR, os.X_OK): - os.system('chmod -x %s' % MONITOR) - - -@additional_config -def boardSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def gpuMem(): - return { - 'label': 'GPU Memory', - 'description': 'set the amount of memory reserved for the GPU (choose at least 96MB if you use the CSI camera board)', - 'type': 'number', - 'min': '16', - 'max': '448', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def cameraLed(): - return { - 'label': 'Enable CSI Camera Led', - 'description': 'control the led on the CSI camera board', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def overclock(): - return { - 'label': 'Overclocking', - 'description': 'choose an overclocking preset for your Raspberry PI', - 'type': 'choices', - 'choices': [ - ('700|250|400|0', 'none (700/250/400/0)'), - ('800|250|400|0', 'modest (800/250/400/0)'), - ('900|250|450|0', 'medium (900/250/450/0)'), - ('950|250|450|0', 'high (950/250/450/0)'), - ('1000|500|600|6', 'turbo (1000/500/600/6)'), - ('1001|300|450|6', 'PiZero (1000/300/450/6)'), - ], - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def sysMon(): - return { - 'label': 'Enable System Monitoring', - 'description': 'when this is enabled, system monitoring info will be overlaid on top of the first camera frame', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': False, - 'get': _get_sys_mon, - 'set': _set_sys_mon - } - diff --git a/board/raspberrypi/motioneye-modules/streameyectl.py b/board/raspberrypi/motioneye-modules/streameyectl.py deleted file mode 100644 index 5f751332f4..0000000000 --- a/board/raspberrypi/motioneye-modules/streameyectl.py +++ /dev/null @@ -1,1172 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import config -import hashlib -import logging -import os.path -import re - -from tornado.ioloop import IOLoop - -import settings - -from config import additional_config - - -MOTIONEYE_CONF = '/data/etc/motioneye.conf' -RASPIMJPEG_CONF = '/data/etc/raspimjpeg.conf' -STREAMEYE_CONF = '/data/etc/streameye.conf' - -EXPOSURE_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('night', 'Night'), - ('nightpreview', 'Night Preview'), - ('backlight', 'Backlight'), - ('spotlight', 'Spotlight'), - ('sports', 'Sports'), - ('snow', 'Snow'), - ('beach', 'Beach'), - ('verylong', 'Very Long'), - ('fixedfps', 'Fixed FPS'), - ('antishake', 'Antishake'), - ('fireworks', 'Fireworks') -] - -AWB_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('sunlight', 'Sunlight'), - ('cloudy', 'Cloudy'), - ('shade', 'Shade'), - ('tungsten', 'Tungsten'), - ('fluorescent', 'Fluorescent'), - ('incandescent', 'Incandescent'), - ('flash', 'Flash'), - ('horizon', 'Horizon') -] - -METERING_CHOICES = [ - ('average', 'Average'), - ('spot', 'Spot'), - ('backlit', 'Backlit'), - ('matrix', 'Matrix') -] - -DRC_CHOICES = [ - ('off', 'Off'), - ('low', 'Low'), - ('medium', 'Medium'), - ('high', 'High') -] - -IMXFX_CHOICES = [ - ('none', 'None'), - ('negative', 'Negative'), - ('solarize', 'Solarize'), - ('sketch', 'Sketch'), - ('denoise', 'Denoise'), - ('emboss', 'Emboss'), - ('oilpaint', 'Oilpaint'), - ('hatch', 'Hatch'), - ('gpen', 'G Pen'), - ('pastel', 'Pastel'), - ('watercolor', 'Water Color'), - ('film', 'Film'), - ('blur', 'Blur'), - ('saturation', 'Saturation'), - ('colorswap', 'Color Swap'), - ('washedout', 'Washed Out'), - ('posterise', 'Posterize'), - ('colorpoint', 'Color Point'), - ('colorbalance', 'Color Balance'), - ('cartoon', 'Cartoon'), - ('deinterlace1', 'Deinterlace 1'), - ('deinterlace2', 'Deinterlace 2') -] - -RESOLUTION_CHOICES = [ - ('320x200', '320x200'), - ('320x240', '320x240'), - ('640x480', '640x480'), - ('800x480', '800x480'), - ('800x600', '800x600'), - ('1024x576', '1024x576'), - ('1024x768', '1024x768'), - ('1280x720', '1280x720'), - ('1280x800', '1280x800'), - ('1280x960', '1280x960'), - ('1280x1024', '1280x1024'), - ('1296x972', '1296x972'), - ('1440x960', '1440x960'), - ('1440x1024', '1440x1024'), - ('1600x1200', '1600x1200'), - ('1640x922', '1640x922'), - ('1640x1232', '1640x1232'), - ('1920x1080', '1920x1080'), - ('2592x1944', '2592x1944'), - ('3280x2464', '3280x2464') -] - -ROTATION_CHOICES = [ - ('0', '0°'), - ('90', '90°'), - ('180', '180°'), - ('270', '270°') -] - -AUTH_CHOICES = [ - ('disabled', 'Disabled'), - ('basic', 'Basic'), -] - -_streameye_enabled = None - - -def _get_streameye_enabled(): - global _streameye_enabled - - if _streameye_enabled is not None: - return _streameye_enabled - - camera_ids = config.get_camera_ids(filter_valid=False) # filter_valid prevents infinte recursion - if len(camera_ids) != 1: - _streameye_enabled = False - return False - - camera_config = config.get_camera(camera_ids[0], as_lines=True) # as_lines prevents infinte recursion - camera_config = config._conf_to_dict(camera_config) - if camera_config.get('@proto') != 'mjpeg': - _streameye_enabled = False - return False - if '127.0.0.1:' not in camera_config.get('@url', ''): - _streameye_enabled = False - return False - - _streameye_enabled = True - return True - - -def _set_streameye_enabled_deferred(enabled): - was_enabled = _get_streameye_enabled() - if enabled and not was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, True) - - elif not enabled and was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, False) - - if enabled: - # this will force updating streameye settings whenever the surveillance credentials are changed - streameye_settings = _get_streameye_settings(1) - _set_streameye_settings(1, streameye_settings) - - -def _set_streameye_enabled(enabled): - global _streameye_enabled - - if enabled: - logging.debug('removing all cameras from cache') - config._camera_config_cache = {} - config._camera_ids_cache = [] - - logging.debug('disabling all cameras in motion.conf') - cmd = 'sed -r -i "s/^thread (.*)/#thread \\1/" /data/etc/motion.conf &>/dev/null' - if os.system(cmd): - logging.error('failed to disable cameras in motion.conf') - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name + '.bak')) - - logging.debug('adding simple mjpeg camera') - - streameye_settings = _get_streameye_settings(1) - main_config = config.get_main() - - device_details = { - 'proto': 'mjpeg', - 'host': '127.0.0.1', - 'port': streameye_settings['sePort'], - 'username': '', - 'password': '', - 'scheme': 'http', - 'path': '/' - } - - if streameye_settings['seAuthMode'] == 'basic': - device_details['username'] = main_config['@normal_username'] - device_details['password'] = main_config['@normal_password'] - - _streameye_enabled = True - config._additional_structure_cache = {} - camera_config = config.add_camera(device_details) - - # call set_camera again so that the streamEye-related defaults are saved - config.set_camera(camera_config['@id'], camera_config) - - _set_motioneye_add_remove_cameras(False) - - else: # disabled - logging.debug('removing simple mjpeg camera') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - if camera_config.get('@proto') == 'mjpeg': - config.rem_camera(camera_id) - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf.bak$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name[:-4])) - - _streameye_enabled = False - config.invalidate() - - logging.debug('enabling all cameras') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - camera_config['@enabled'] = True - config.set_camera(camera_id, camera_config) - - _set_motioneye_add_remove_cameras(True) - - -def _set_motioneye_add_remove_cameras(enabled): - logging.debug('%s motionEye add/remove cameras' % ['disabling', 'enabling'][enabled]) - - lines = [] - found = False - if os.path.exists(MOTIONEYE_CONF): - with open(MOTIONEYE_CONF) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - try: - name, _ = line.split(' ', 2) - - except: - continue - - name = name.replace('_', '-') - - if name == 'add-remove-cameras': - lines[i] = 'add-remove-cameras %s' % str(enabled).lower() - found = True - - if not found: - lines.append('add-remove-cameras %s' % str(enabled).lower()) - - with open(MOTIONEYE_CONF, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_raspimjpeg_settings(camera_id): - s = { - 'preview': False, - 'brightness': 50, - 'contrast': 0, - 'saturation': 0, - 'sharpness': 0, - 'iso': 400, - 'ev': 0, - 'shutter': 0, - 'exposure': 'auto', - 'awb': 'auto', - 'metering': 'average', - 'drc': 'off', - 'vstab': False, - 'denoise': False, - 'imxfx': 'none', - 'width': 640, - 'height': 480, - 'rotation': 0, - 'vflip': False, - 'hflip': False, - 'framerate': 15, - 'quality': 25, - 'zoomx': 0, - 'zoomy': 0, - 'zoomw': 100, - 'zoomh': 100 - } - - if os.path.exists(RASPIMJPEG_CONF): - logging.debug('reading raspimjpeg settings from %s' % RASPIMJPEG_CONF) - - with open(RASPIMJPEG_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - try: - name, value = line.split(' ', 1) - - except: - continue - - name = name.replace('_', '-') - - try: - value = int(value) - - except: - pass - - if value == 'false': - value = False - - elif value == 'true': - value = True - - if name == 'zoom': - try: - parts = value.split(',') - s['zoomx'] = int(float(parts[0]) * 100) - s['zoomy'] = int(float(parts[1]) * 100) - s['zoomw'] = int(float(parts[2]) * 100) - s['zoomh'] = int(float(parts[3]) * 100) - - except: - logging.error('failed to parse zoom setting "%s"' % value) - - continue - - s[name] = value - - s['contrast'] = (s['contrast'] + 100) / 2 - s['saturation'] = (s['saturation'] + 100) / 2 - s['sharpness'] = (s['sharpness'] + 100) / 2 - - s['resolution'] = '%sx%s' % (s.pop('width'), s.pop('height')) - - s = dict(('se' + n[0].upper() + n[1:], v) for (n, v) in s.items()) - - return s - - -def _set_raspimjpeg_settings(camera_id, s): - s = dict((n[2].lower() + n[3:], v) for (n, v) in s.items()) - - s['width'] = int(s['resolution'].split('x')[0]) - s['height'] = int(s.pop('resolution').split('x')[1]) - - s['zoom'] = '%.2f,%.2f,%.2f,%.2f' % ( - s.pop('zoomx') / 100.0, s.pop('zoomy') / 100.0, - s.pop('zoomw') / 100.0, s.pop('zoomh') / 100.0) - - s['contrast'] = s['contrast'] * 2 - 100 - s['saturation'] = s['saturation'] * 2 - 100 - s['sharpness'] = s['sharpness'] * 2 - 100 - - logging.debug('writing raspimjpeg settings to %s' % RASPIMJPEG_CONF) - - lines = [] - for name, value in sorted(s.items(), key=lambda i: i[0]): - if isinstance(value, bool): - value = str(value).lower() - - line = '%s %s\n' % (name, value) - lines.append(line) - - with open(RASPIMJPEG_CONF, 'w') as f: - for line in lines: - f.write(line) - - -def _get_streameye_settings(camera_id): - s = { - 'seAuthMode': 'disabled', - 'sePort': 8081, - } - - if os.path.exists(STREAMEYE_CONF): - logging.debug('reading streameye settings from %s' % STREAMEYE_CONF) - - with open(STREAMEYE_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - m = re.findall('PORT="?(\d+)"?', line) - if m: - s['sePort'] = int(m[0]) - continue - - m = re.findall('AUTH="?(\w+)"?', line) - if m: - s['seAuthMode'] = m[0] - - return s - - -def _set_streameye_settings(camera_id, s): - s = dict(s) - s.setdefault('sePort', 8081) - s.setdefault('seAuthMode', 'disabled') - - main_config = config.get_main() - username = main_config['@normal_username'] - password = main_config['@normal_password'] - realm = 'motionEyeOS' - - logging.debug('writing streameye settings to %s' % STREAMEYE_CONF) - - lines = [ - 'PORT="%s"' % s['sePort'], - 'AUTH="%s"' % s['seAuthMode'], - 'CREDENTIALS="%s:%s:%s"' % (username, password, realm) - ] - - with open(STREAMEYE_CONF, 'w') as f: - for line in lines: - f.write(line + '\n') - - if 1 in config.get_camera_ids(): - # a workaround to update the camera username and password - # since we cannot call set_camera() from here - if s['seAuthMode'] == 'basic': - url = 'http://%s:%s@127.0.0.1:%s/' % (username, password, s['sePort']) - - else: - url = 'http://127.0.0.1:%s/' % s['sePort'] - - if 1 in config._camera_config_cache: - logging.debug('updating streaming authentication in config cache') - config._camera_config_cache[1]['@url'] = url - - lines = config.get_camera(1, as_lines=True) - for i, line in enumerate(lines): - if line.startswith('# @url'): - lines[i] = '# @url %s' % url - - config_file = os.path.join(settings.CONF_PATH, config._CAMERA_CONFIG_FILE_NAME % {'id': 1}) - logging.debug('updating streaming authentication in camera config file %s' % config_file) - with open(config_file, 'w') as f: - for line in lines: - f.write(line + '\n') - - logging.debug('restarting streameye') - if os.system('streameye.sh restart'): - logging.error('streameye restart failed') - - -# make streameye-related log files downloadable - -if _get_streameye_enabled(): - def _add_log_handlers(): - import handlers - handlers.LogHandler.LOGS['streameye'] = (os.path.join(settings.LOG_PATH, 'streameye.log'), 'streameye.log') - handlers.LogHandler.LOGS['raspimjpeg'] = (os.path.join(settings.LOG_PATH, 'raspimjpeg.log'), 'raspimjpeg.log') - - # handlers.LogHandler is not yet available - # at the time streameyectl is imported - io_loop = IOLoop.instance() - io_loop.add_callback(_add_log_handlers) - - @additional_config - def streamEyeLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'streameye.log', - } - - @additional_config - def raspiMjpegLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'raspimjpeg.log', - } - - -@additional_config -def streamEyeMainSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def streamEye(): - return { - 'label': 'Fast Network Camera', - 'description': 'Enabling this option will turn your Raspberry PI into a simple and fast MJPEG network camera, ' + - 'disabling motion detection, media files and all other advanced features (works only with the CSI camera)', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_streameye_enabled, - 'set': _set_streameye_enabled_deferred, - } - - -@additional_config -def streamEyeCameraSeparator1(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seBrightness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Brightness', - 'description': 'sets a desired brightness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seContrast(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Contrast', - 'description': 'sets a desired contrast level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSaturation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Saturation', - 'description': 'sets a desired saturation level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSharpness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Sharpness', - 'description': 'sets a desired sharpness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - - -@additional_config -def streamEyeCameraSeparator2(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seResolution(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Resolution', - 'description': 'the video resolution (larger values produce better quality but require more CPU power, larger storage space and bandwidth)', - 'type': 'choices', - 'choices': RESOLUTION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seRotation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Rotation', - 'description': 'use this to rotate the captured image, if your camera is not positioned correctly', - 'type': 'choices', - 'choices': ROTATION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Vertically', - 'description': 'enable this to flip the captured image vertically', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seHflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Horizontally', - 'description': 'enable this to flip the captured image horizontally', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seFramerate(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Frame Rate', - 'description': 'sets the number of frames captured by the camera every second (higher values produce smoother videos but require more CPU power, larger storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 30, - 'snap': 0, - 'ticks': "1|5|10|15|20|25|30", - 'decimals': 0, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seQuality(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Quality', - 'description': 'sets the JPEG image quality (higher values produce a better image quality but require more storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 100, - 'snap': 2, - 'ticks': '1|25|50|75|100', - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom X', - 'description': 'sets the horizontal zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomy(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Y', - 'description': 'sets the vertical zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomw(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Width', - 'description': 'sets the zoom width', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomh(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Height', - 'description': 'sets the zoom height', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePreview(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'HDMI Preview', - 'description': 'enable this if you want to see the preview on an HDMI-connected monitor', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator3(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seIso(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'ISO', - 'description': 'sets a desired ISO level for this camera', - 'type': 'range', - 'min': 100, - 'max': 800, - 'snap': 1, - 'ticksnum': 8, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seShutter(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Shutter Speed', - 'description': 'sets a desired shutter speed for this camera', - 'type': 'number', - 'min': 0, - 'max': 6000000, - 'unit': 'microseconds', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator4(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seExposure(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Mode', - 'description': 'sets a desired exposure mode for this camera', - 'type': 'choices', - 'choices': EXPOSURE_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seEv(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Compensation', - 'description': 'sets a desired exposure compensation for this camera', - 'type': 'range', - 'min': -25, - 'max': 25, - 'snap': 1, - 'ticksnum': 11, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seAwb(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Automatic White Balance', - 'description': 'sets a desired automatic white balance mode for this camera', - 'type': 'choices', - 'choices': AWB_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seMetering(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Metering Mode', - 'description': 'sets a desired metering mode for this camera', - 'type': 'choices', - 'choices': METERING_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDrc(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Dynamic Range Compensation', - 'description': 'sets a desired dynamic range compensation level for this camera', - 'type': 'choices', - 'choices': DRC_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVstab(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Stabilization', - 'description': 'enables or disables video stabilization for this camera', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDenoise(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Denoise', - 'description': 'enables image denoising', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seImxfx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Effect', - 'description': 'sets a desired image effect for this camera', - 'type': 'choices', - 'choices': IMXFX_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePort(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Streaming Port', - 'description': 'sets the TCP port on which the webcam streaming server listens', - 'type': 'number', - 'min': 1024, - 'max': 65535, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - - -@additional_config -def seAuthMode(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Authentication Mode', - 'description': 'the authentication mode to use when accessing the stream (use Basic instead of Digest if you encounter issues with third party apps)', - 'type': 'choices', - 'choices': AUTH_CHOICES, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - diff --git a/board/raspberrypi/overlay/etc/init.d/S84streameye b/board/raspberrypi/overlay/etc/init.d/S84streameye deleted file mode 100755 index 81e2e2c896..0000000000 --- a/board/raspberrypi/overlay/etc/init.d/S84streameye +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -motioneye_conf_dir="/data/etc/" - -test -n "$os_version" || source /etc/init.d/base - -enabled() { - test $(ls -1 $motioneye_conf_dir/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1 - - grep '# @proto mjpeg' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - grep -E '# @url http://(.*)127.0.0.1:' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - return 0 -} - -enabled || exit 0 - -start() { - msg_begin "Starting streameye" - streameye.sh start - test $? == 0 && msg_done || msg_fail -} - -stop() { - msg_begin "Stopping streameye" - streameye.sh stop - test $? == 0 && msg_done || msg_fail -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/raspberrypi/overlay/etc/modules b/board/raspberrypi/overlay/etc/modules deleted file mode 100644 index 2990e0b8e0..0000000000 --- a/board/raspberrypi/overlay/etc/modules +++ /dev/null @@ -1,3 +0,0 @@ -bcm2835-v4l2 max_video_width=2592 max_video_height=1944 -bcm2835-wdt - diff --git a/board/raspberrypi/overlay/usr/bin/streameye.sh b/board/raspberrypi/overlay/usr/bin/streameye.sh deleted file mode 100755 index 29e5b79d8b..0000000000 --- a/board/raspberrypi/overlay/usr/bin/streameye.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -RASPIMJPEG_CONF=/data/etc/raspimjpeg.conf -RASPIMJPEG_LOG=/var/log/raspimjpeg.log -MOTIONEYE_CONF=/data/etc/motioneye.conf -STREAMEYE_CONF=/data/etc/streameye.conf -STREAMEYE_LOG=/var/log/streameye.log - -test -r $RASPIMJPEG_CONF || exit 1 -test -r $STREAMEYE_CONF || exit 1 - -watch() { - count=0 - while true; do - sleep 5 - if ! ps aux | grep raspimjpeg.py | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - fi - done -} - -function start() { - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -n "$pid" ]; then - return - fi - - raspimjpeg_opts="" - while read line; do - if echo "$line" | grep false &>/dev/null; then - continue - fi - if echo "$line" | grep true &>/dev/null; then - line=$(echo $line | cut -d ' ' -f 1) - fi - raspimjpeg_opts="$raspimjpeg_opts --$line" - done < $RASPIMJPEG_CONF - - source $STREAMEYE_CONF - streameye_opts="-p $PORT" - if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then - streameye_opts="$streameye_opts -a basic -c $CREDENTIALS" - fi - - if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then - raspimjpeg_opts="$raspimjpeg_opts -d" - streameye_opts="$streameye_opts -d" - fi - - raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG & -} - -function stop() { - # stop the streameye background watch process - ps | grep streameye.sh | grep -v $$ | grep -v S94streameye| grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - - # stop the raspimjpeg process - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -z "$pid" ]; then - return - fi - - kill -HUP "$pid" &>/dev/null - count=0 - while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do - sleep 1 - count=$(($count + 1)) - done - kill -KILL "$pid" &>/dev/null || true -} - -case "$1" in - start) - start - watch & - ;; - - stop) - stop - ;; - - restart) - stop - start - watch & - ;; - - *) - echo $"Usage: $0 {start|stop|restart}" - exit 1 -esac - diff --git a/board/raspberrypi2/motioneye-modules/boardctl.py b/board/raspberrypi2/motioneye-modules/boardctl.py deleted file mode 100644 index c162502ced..0000000000 --- a/board/raspberrypi2/motioneye-modules/boardctl.py +++ /dev/null @@ -1,290 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import logging -import os.path - -from config import additional_config - -import streameyectl - - -CONFIG_TXT = '/boot/config.txt' -MONITOR = '/data/etc/monitor_1' - -MONITOR_SCRIPT = '''#!/bin/bash - -net_tmp=/tmp/netspeed.tmp -temp=$(($(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)) -load=$(cat /proc/loadavg | cut -d ' ' -f 2) -recv=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 3 | tail -n +3 | awk '{s+=$1} END {print s}') -send=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 11 | tail -n +3 | awk '{s+=$1} END {print s}') -total=$(($recv + $send)) - -if [ -e $net_tmp ]; then - prev_total=$(cat $net_tmp) - speed=$(($total - $prev_total)) -else - speed=0 -fi - -echo $total > $net_tmp -speed=$(($speed / 1024)) - -echo -n "$temp°|$load|${speed}kB/s" -''' - -OVERCLOCK = { - 700: '700|250|400|0', - 800: '800|250|400|0', - 900: '900|250|450|0', - 950: '950|250|450|0', - 1000: '1000|500|600|6', - 1001: '1001|500|500|2' -} - -def _get_board_settings(): - gpu_mem = 128 - camera_led = True - arm_freq = 1001 - - if os.path.exists(CONFIG_TXT): - logging.debug('reading board settings from %s' % CONFIG_TXT) - - with open(CONFIG_TXT) as f: - for line in f: - line = line.strip() - if not line or line.startswith('#'): - continue - - parts = line.split('=', 1) - if len(parts) != 2: - continue - - name, value = parts - name = name.strip() - value = value.strip() - - if name == 'gpu_mem': - gpu_mem = int(value) - - elif name == 'arm_freq': - arm_freq = int(value) - - elif name == 'disable_camera_led': - camera_led = value == '0' - - overclock = OVERCLOCK.get(arm_freq, '700|250|400|0') - - s = { - 'gpuMem': gpu_mem, - 'overclock': overclock, - 'cameraLed': camera_led - } - - logging.debug('board settings: gpu_mem=%(gpuMem)s, overclock=%(overclock)s, camera_led=%(cameraLed)s' % s) - - return s - - -def _set_board_settings(s): - s.setdefault('gpuMem', 128) - s.setdefault('overclock', '700|250|400|0') - s.setdefault('cameraLed', True) - - old_settings = _get_board_settings() - if s == old_settings: - return # nothing has changed - - seen = set() - - logging.debug('writing board settings to %s: ' % CONFIG_TXT + - 'gpu_mem=%(gpuMem)s, overclock=%(overclock)s, camera_led=%(cameraLed)s' % s) - - arm_freq, gpu_freq, sdram_freq, over_voltage = s['overclock'].split('|') - - lines = [] - if os.path.exists(CONFIG_TXT): - with open(CONFIG_TXT) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - line = line.strip('#') - - try: - name, _ = line.split('=', 1) - name = name.strip() - - except: - continue - - seen.add(name) - - if name == 'gpu_mem': - lines[i] = '%s=%s' % (name, s['gpuMem']) - - elif name == 'arm_freq': - lines[i] = 'arm_freq=%s' % arm_freq - - elif name in ['gpu_freq', 'core_freq']: - lines[i] = '%s=%s' % (name, gpu_freq) - - elif name == 'sdram_freq': - lines[i] = 'sdram_freq=%s' % sdram_freq - - elif name == 'over_voltage': - lines[i] = 'over_voltage=%s' % over_voltage - - elif name == 'disable_camera_led': - lines[i] = 'disable_camera_led=%s' % ['1', '0'][s['cameraLed']] - - if 'gpu_mem' not in seen: - lines.append('gpu_mem=%s' % s['gpuMem']) - - if 'arm_freq' not in seen: - lines.append('arm_freq=%s' % arm_freq) - - if 'gpu_freq' not in seen: - lines.append('gpu_freq=%s' % gpu_freq) - - if 'sdram_freq' not in seen: - lines.append('sdram_freq=%s' % sdram_freq) - - if 'over_voltage' not in seen: - lines.append('over_voltage=%s' % over_voltage) - - if 'disable_camera_led' not in seen: - lines.append('disable_camera_led=%s' % ['1', '0'][s['cameraLed']]) - - logging.debug('remounting /boot read-write') - if os.system('mount -o remount,rw /boot'): - logging.error('failed to remount /boot read-write') - - with open(CONFIG_TXT, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_sys_mon(): - return os.access(MONITOR, os.X_OK) - - -def _set_sys_mon(sys_mon): - if sys_mon: - if os.access(MONITOR, os.X_OK): - pass - - else: - if os.path.exists(MONITOR): - os.system('chmod +x %s' % MONITOR) - - else: - with open(MONITOR, 'w') as f: - f.write(MONITOR_SCRIPT) - - os.system('chmod +x %s' % MONITOR) - - else: - if os.access(MONITOR, os.X_OK): - os.system('chmod -x %s' % MONITOR) - - -@additional_config -def boardSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def gpuMem(): - return { - 'label': 'GPU Memory', - 'description': 'set the amount of memory reserved for the GPU (choose at least 96MB if you use the CSI camera board)', - 'type': 'number', - 'min': '16', - 'max': '944', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def cameraLed(): - return { - 'label': 'Enable CSI Camera Led', - 'description': 'control the led on the CSI camera board', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def overclock(): - return { - 'label': 'Overclocking', - 'description': 'choose an overclocking preset for your Raspberry PI', - 'type': 'choices', - 'choices': [ - ('700|250|400|0', 'none (700/250/400/0)'), - ('800|250|400|0', 'modest (800/250/400/0)'), - ('900|250|450|0', 'medium (900/250/450/0)'), - ('950|250|450|0', 'high (950/250/450/0)'), - ('1000|500|600|6', 'turbo (1000/500/600/6)'), - ('1001|500|500|2', 'Pi2 (1000/500/500/2)') - ], - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def sysMon(): - return { - 'label': 'Enable System Monitoring', - 'description': 'when this is enabled, system monitoring info will be overlaid on top of the first camera frame', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': False, - 'get': _get_sys_mon, - 'set': _set_sys_mon - } - diff --git a/board/raspberrypi2/motioneye-modules/streameyectl.py b/board/raspberrypi2/motioneye-modules/streameyectl.py deleted file mode 100644 index 5f751332f4..0000000000 --- a/board/raspberrypi2/motioneye-modules/streameyectl.py +++ /dev/null @@ -1,1172 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import config -import hashlib -import logging -import os.path -import re - -from tornado.ioloop import IOLoop - -import settings - -from config import additional_config - - -MOTIONEYE_CONF = '/data/etc/motioneye.conf' -RASPIMJPEG_CONF = '/data/etc/raspimjpeg.conf' -STREAMEYE_CONF = '/data/etc/streameye.conf' - -EXPOSURE_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('night', 'Night'), - ('nightpreview', 'Night Preview'), - ('backlight', 'Backlight'), - ('spotlight', 'Spotlight'), - ('sports', 'Sports'), - ('snow', 'Snow'), - ('beach', 'Beach'), - ('verylong', 'Very Long'), - ('fixedfps', 'Fixed FPS'), - ('antishake', 'Antishake'), - ('fireworks', 'Fireworks') -] - -AWB_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('sunlight', 'Sunlight'), - ('cloudy', 'Cloudy'), - ('shade', 'Shade'), - ('tungsten', 'Tungsten'), - ('fluorescent', 'Fluorescent'), - ('incandescent', 'Incandescent'), - ('flash', 'Flash'), - ('horizon', 'Horizon') -] - -METERING_CHOICES = [ - ('average', 'Average'), - ('spot', 'Spot'), - ('backlit', 'Backlit'), - ('matrix', 'Matrix') -] - -DRC_CHOICES = [ - ('off', 'Off'), - ('low', 'Low'), - ('medium', 'Medium'), - ('high', 'High') -] - -IMXFX_CHOICES = [ - ('none', 'None'), - ('negative', 'Negative'), - ('solarize', 'Solarize'), - ('sketch', 'Sketch'), - ('denoise', 'Denoise'), - ('emboss', 'Emboss'), - ('oilpaint', 'Oilpaint'), - ('hatch', 'Hatch'), - ('gpen', 'G Pen'), - ('pastel', 'Pastel'), - ('watercolor', 'Water Color'), - ('film', 'Film'), - ('blur', 'Blur'), - ('saturation', 'Saturation'), - ('colorswap', 'Color Swap'), - ('washedout', 'Washed Out'), - ('posterise', 'Posterize'), - ('colorpoint', 'Color Point'), - ('colorbalance', 'Color Balance'), - ('cartoon', 'Cartoon'), - ('deinterlace1', 'Deinterlace 1'), - ('deinterlace2', 'Deinterlace 2') -] - -RESOLUTION_CHOICES = [ - ('320x200', '320x200'), - ('320x240', '320x240'), - ('640x480', '640x480'), - ('800x480', '800x480'), - ('800x600', '800x600'), - ('1024x576', '1024x576'), - ('1024x768', '1024x768'), - ('1280x720', '1280x720'), - ('1280x800', '1280x800'), - ('1280x960', '1280x960'), - ('1280x1024', '1280x1024'), - ('1296x972', '1296x972'), - ('1440x960', '1440x960'), - ('1440x1024', '1440x1024'), - ('1600x1200', '1600x1200'), - ('1640x922', '1640x922'), - ('1640x1232', '1640x1232'), - ('1920x1080', '1920x1080'), - ('2592x1944', '2592x1944'), - ('3280x2464', '3280x2464') -] - -ROTATION_CHOICES = [ - ('0', '0°'), - ('90', '90°'), - ('180', '180°'), - ('270', '270°') -] - -AUTH_CHOICES = [ - ('disabled', 'Disabled'), - ('basic', 'Basic'), -] - -_streameye_enabled = None - - -def _get_streameye_enabled(): - global _streameye_enabled - - if _streameye_enabled is not None: - return _streameye_enabled - - camera_ids = config.get_camera_ids(filter_valid=False) # filter_valid prevents infinte recursion - if len(camera_ids) != 1: - _streameye_enabled = False - return False - - camera_config = config.get_camera(camera_ids[0], as_lines=True) # as_lines prevents infinte recursion - camera_config = config._conf_to_dict(camera_config) - if camera_config.get('@proto') != 'mjpeg': - _streameye_enabled = False - return False - if '127.0.0.1:' not in camera_config.get('@url', ''): - _streameye_enabled = False - return False - - _streameye_enabled = True - return True - - -def _set_streameye_enabled_deferred(enabled): - was_enabled = _get_streameye_enabled() - if enabled and not was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, True) - - elif not enabled and was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, False) - - if enabled: - # this will force updating streameye settings whenever the surveillance credentials are changed - streameye_settings = _get_streameye_settings(1) - _set_streameye_settings(1, streameye_settings) - - -def _set_streameye_enabled(enabled): - global _streameye_enabled - - if enabled: - logging.debug('removing all cameras from cache') - config._camera_config_cache = {} - config._camera_ids_cache = [] - - logging.debug('disabling all cameras in motion.conf') - cmd = 'sed -r -i "s/^thread (.*)/#thread \\1/" /data/etc/motion.conf &>/dev/null' - if os.system(cmd): - logging.error('failed to disable cameras in motion.conf') - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name + '.bak')) - - logging.debug('adding simple mjpeg camera') - - streameye_settings = _get_streameye_settings(1) - main_config = config.get_main() - - device_details = { - 'proto': 'mjpeg', - 'host': '127.0.0.1', - 'port': streameye_settings['sePort'], - 'username': '', - 'password': '', - 'scheme': 'http', - 'path': '/' - } - - if streameye_settings['seAuthMode'] == 'basic': - device_details['username'] = main_config['@normal_username'] - device_details['password'] = main_config['@normal_password'] - - _streameye_enabled = True - config._additional_structure_cache = {} - camera_config = config.add_camera(device_details) - - # call set_camera again so that the streamEye-related defaults are saved - config.set_camera(camera_config['@id'], camera_config) - - _set_motioneye_add_remove_cameras(False) - - else: # disabled - logging.debug('removing simple mjpeg camera') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - if camera_config.get('@proto') == 'mjpeg': - config.rem_camera(camera_id) - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf.bak$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name[:-4])) - - _streameye_enabled = False - config.invalidate() - - logging.debug('enabling all cameras') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - camera_config['@enabled'] = True - config.set_camera(camera_id, camera_config) - - _set_motioneye_add_remove_cameras(True) - - -def _set_motioneye_add_remove_cameras(enabled): - logging.debug('%s motionEye add/remove cameras' % ['disabling', 'enabling'][enabled]) - - lines = [] - found = False - if os.path.exists(MOTIONEYE_CONF): - with open(MOTIONEYE_CONF) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - try: - name, _ = line.split(' ', 2) - - except: - continue - - name = name.replace('_', '-') - - if name == 'add-remove-cameras': - lines[i] = 'add-remove-cameras %s' % str(enabled).lower() - found = True - - if not found: - lines.append('add-remove-cameras %s' % str(enabled).lower()) - - with open(MOTIONEYE_CONF, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_raspimjpeg_settings(camera_id): - s = { - 'preview': False, - 'brightness': 50, - 'contrast': 0, - 'saturation': 0, - 'sharpness': 0, - 'iso': 400, - 'ev': 0, - 'shutter': 0, - 'exposure': 'auto', - 'awb': 'auto', - 'metering': 'average', - 'drc': 'off', - 'vstab': False, - 'denoise': False, - 'imxfx': 'none', - 'width': 640, - 'height': 480, - 'rotation': 0, - 'vflip': False, - 'hflip': False, - 'framerate': 15, - 'quality': 25, - 'zoomx': 0, - 'zoomy': 0, - 'zoomw': 100, - 'zoomh': 100 - } - - if os.path.exists(RASPIMJPEG_CONF): - logging.debug('reading raspimjpeg settings from %s' % RASPIMJPEG_CONF) - - with open(RASPIMJPEG_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - try: - name, value = line.split(' ', 1) - - except: - continue - - name = name.replace('_', '-') - - try: - value = int(value) - - except: - pass - - if value == 'false': - value = False - - elif value == 'true': - value = True - - if name == 'zoom': - try: - parts = value.split(',') - s['zoomx'] = int(float(parts[0]) * 100) - s['zoomy'] = int(float(parts[1]) * 100) - s['zoomw'] = int(float(parts[2]) * 100) - s['zoomh'] = int(float(parts[3]) * 100) - - except: - logging.error('failed to parse zoom setting "%s"' % value) - - continue - - s[name] = value - - s['contrast'] = (s['contrast'] + 100) / 2 - s['saturation'] = (s['saturation'] + 100) / 2 - s['sharpness'] = (s['sharpness'] + 100) / 2 - - s['resolution'] = '%sx%s' % (s.pop('width'), s.pop('height')) - - s = dict(('se' + n[0].upper() + n[1:], v) for (n, v) in s.items()) - - return s - - -def _set_raspimjpeg_settings(camera_id, s): - s = dict((n[2].lower() + n[3:], v) for (n, v) in s.items()) - - s['width'] = int(s['resolution'].split('x')[0]) - s['height'] = int(s.pop('resolution').split('x')[1]) - - s['zoom'] = '%.2f,%.2f,%.2f,%.2f' % ( - s.pop('zoomx') / 100.0, s.pop('zoomy') / 100.0, - s.pop('zoomw') / 100.0, s.pop('zoomh') / 100.0) - - s['contrast'] = s['contrast'] * 2 - 100 - s['saturation'] = s['saturation'] * 2 - 100 - s['sharpness'] = s['sharpness'] * 2 - 100 - - logging.debug('writing raspimjpeg settings to %s' % RASPIMJPEG_CONF) - - lines = [] - for name, value in sorted(s.items(), key=lambda i: i[0]): - if isinstance(value, bool): - value = str(value).lower() - - line = '%s %s\n' % (name, value) - lines.append(line) - - with open(RASPIMJPEG_CONF, 'w') as f: - for line in lines: - f.write(line) - - -def _get_streameye_settings(camera_id): - s = { - 'seAuthMode': 'disabled', - 'sePort': 8081, - } - - if os.path.exists(STREAMEYE_CONF): - logging.debug('reading streameye settings from %s' % STREAMEYE_CONF) - - with open(STREAMEYE_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - m = re.findall('PORT="?(\d+)"?', line) - if m: - s['sePort'] = int(m[0]) - continue - - m = re.findall('AUTH="?(\w+)"?', line) - if m: - s['seAuthMode'] = m[0] - - return s - - -def _set_streameye_settings(camera_id, s): - s = dict(s) - s.setdefault('sePort', 8081) - s.setdefault('seAuthMode', 'disabled') - - main_config = config.get_main() - username = main_config['@normal_username'] - password = main_config['@normal_password'] - realm = 'motionEyeOS' - - logging.debug('writing streameye settings to %s' % STREAMEYE_CONF) - - lines = [ - 'PORT="%s"' % s['sePort'], - 'AUTH="%s"' % s['seAuthMode'], - 'CREDENTIALS="%s:%s:%s"' % (username, password, realm) - ] - - with open(STREAMEYE_CONF, 'w') as f: - for line in lines: - f.write(line + '\n') - - if 1 in config.get_camera_ids(): - # a workaround to update the camera username and password - # since we cannot call set_camera() from here - if s['seAuthMode'] == 'basic': - url = 'http://%s:%s@127.0.0.1:%s/' % (username, password, s['sePort']) - - else: - url = 'http://127.0.0.1:%s/' % s['sePort'] - - if 1 in config._camera_config_cache: - logging.debug('updating streaming authentication in config cache') - config._camera_config_cache[1]['@url'] = url - - lines = config.get_camera(1, as_lines=True) - for i, line in enumerate(lines): - if line.startswith('# @url'): - lines[i] = '# @url %s' % url - - config_file = os.path.join(settings.CONF_PATH, config._CAMERA_CONFIG_FILE_NAME % {'id': 1}) - logging.debug('updating streaming authentication in camera config file %s' % config_file) - with open(config_file, 'w') as f: - for line in lines: - f.write(line + '\n') - - logging.debug('restarting streameye') - if os.system('streameye.sh restart'): - logging.error('streameye restart failed') - - -# make streameye-related log files downloadable - -if _get_streameye_enabled(): - def _add_log_handlers(): - import handlers - handlers.LogHandler.LOGS['streameye'] = (os.path.join(settings.LOG_PATH, 'streameye.log'), 'streameye.log') - handlers.LogHandler.LOGS['raspimjpeg'] = (os.path.join(settings.LOG_PATH, 'raspimjpeg.log'), 'raspimjpeg.log') - - # handlers.LogHandler is not yet available - # at the time streameyectl is imported - io_loop = IOLoop.instance() - io_loop.add_callback(_add_log_handlers) - - @additional_config - def streamEyeLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'streameye.log', - } - - @additional_config - def raspiMjpegLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'raspimjpeg.log', - } - - -@additional_config -def streamEyeMainSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def streamEye(): - return { - 'label': 'Fast Network Camera', - 'description': 'Enabling this option will turn your Raspberry PI into a simple and fast MJPEG network camera, ' + - 'disabling motion detection, media files and all other advanced features (works only with the CSI camera)', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_streameye_enabled, - 'set': _set_streameye_enabled_deferred, - } - - -@additional_config -def streamEyeCameraSeparator1(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seBrightness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Brightness', - 'description': 'sets a desired brightness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seContrast(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Contrast', - 'description': 'sets a desired contrast level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSaturation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Saturation', - 'description': 'sets a desired saturation level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSharpness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Sharpness', - 'description': 'sets a desired sharpness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - - -@additional_config -def streamEyeCameraSeparator2(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seResolution(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Resolution', - 'description': 'the video resolution (larger values produce better quality but require more CPU power, larger storage space and bandwidth)', - 'type': 'choices', - 'choices': RESOLUTION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seRotation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Rotation', - 'description': 'use this to rotate the captured image, if your camera is not positioned correctly', - 'type': 'choices', - 'choices': ROTATION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Vertically', - 'description': 'enable this to flip the captured image vertically', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seHflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Horizontally', - 'description': 'enable this to flip the captured image horizontally', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seFramerate(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Frame Rate', - 'description': 'sets the number of frames captured by the camera every second (higher values produce smoother videos but require more CPU power, larger storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 30, - 'snap': 0, - 'ticks': "1|5|10|15|20|25|30", - 'decimals': 0, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seQuality(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Quality', - 'description': 'sets the JPEG image quality (higher values produce a better image quality but require more storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 100, - 'snap': 2, - 'ticks': '1|25|50|75|100', - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom X', - 'description': 'sets the horizontal zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomy(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Y', - 'description': 'sets the vertical zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomw(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Width', - 'description': 'sets the zoom width', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomh(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Height', - 'description': 'sets the zoom height', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePreview(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'HDMI Preview', - 'description': 'enable this if you want to see the preview on an HDMI-connected monitor', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator3(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seIso(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'ISO', - 'description': 'sets a desired ISO level for this camera', - 'type': 'range', - 'min': 100, - 'max': 800, - 'snap': 1, - 'ticksnum': 8, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seShutter(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Shutter Speed', - 'description': 'sets a desired shutter speed for this camera', - 'type': 'number', - 'min': 0, - 'max': 6000000, - 'unit': 'microseconds', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator4(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seExposure(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Mode', - 'description': 'sets a desired exposure mode for this camera', - 'type': 'choices', - 'choices': EXPOSURE_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seEv(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Compensation', - 'description': 'sets a desired exposure compensation for this camera', - 'type': 'range', - 'min': -25, - 'max': 25, - 'snap': 1, - 'ticksnum': 11, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seAwb(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Automatic White Balance', - 'description': 'sets a desired automatic white balance mode for this camera', - 'type': 'choices', - 'choices': AWB_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seMetering(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Metering Mode', - 'description': 'sets a desired metering mode for this camera', - 'type': 'choices', - 'choices': METERING_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDrc(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Dynamic Range Compensation', - 'description': 'sets a desired dynamic range compensation level for this camera', - 'type': 'choices', - 'choices': DRC_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVstab(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Stabilization', - 'description': 'enables or disables video stabilization for this camera', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDenoise(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Denoise', - 'description': 'enables image denoising', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seImxfx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Effect', - 'description': 'sets a desired image effect for this camera', - 'type': 'choices', - 'choices': IMXFX_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePort(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Streaming Port', - 'description': 'sets the TCP port on which the webcam streaming server listens', - 'type': 'number', - 'min': 1024, - 'max': 65535, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - - -@additional_config -def seAuthMode(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Authentication Mode', - 'description': 'the authentication mode to use when accessing the stream (use Basic instead of Digest if you encounter issues with third party apps)', - 'type': 'choices', - 'choices': AUTH_CHOICES, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - diff --git a/board/raspberrypi2/overlay/etc/init.d/S84streameye b/board/raspberrypi2/overlay/etc/init.d/S84streameye deleted file mode 100755 index 81e2e2c896..0000000000 --- a/board/raspberrypi2/overlay/etc/init.d/S84streameye +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -motioneye_conf_dir="/data/etc/" - -test -n "$os_version" || source /etc/init.d/base - -enabled() { - test $(ls -1 $motioneye_conf_dir/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1 - - grep '# @proto mjpeg' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - grep -E '# @url http://(.*)127.0.0.1:' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - return 0 -} - -enabled || exit 0 - -start() { - msg_begin "Starting streameye" - streameye.sh start - test $? == 0 && msg_done || msg_fail -} - -stop() { - msg_begin "Stopping streameye" - streameye.sh stop - test $? == 0 && msg_done || msg_fail -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/raspberrypi2/overlay/etc/modules b/board/raspberrypi2/overlay/etc/modules deleted file mode 100644 index 2990e0b8e0..0000000000 --- a/board/raspberrypi2/overlay/etc/modules +++ /dev/null @@ -1,3 +0,0 @@ -bcm2835-v4l2 max_video_width=2592 max_video_height=1944 -bcm2835-wdt - diff --git a/board/raspberrypi2/overlay/usr/bin/streameye.sh b/board/raspberrypi2/overlay/usr/bin/streameye.sh deleted file mode 100755 index 8ab060182b..0000000000 --- a/board/raspberrypi2/overlay/usr/bin/streameye.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -RASPIMJPEG_CONF=/data/etc/raspimjpeg.conf -RASPIMJPEG_LOG=/var/log/raspimjpeg.log -MOTIONEYE_CONF=/data/etc/motioneye.conf -STREAMEYE_CONF=/data/etc/streameye.conf -STREAMEYE_LOG=/var/log/streameye.log - -test -r $RASPIMJPEG_CONF || exit 1 -test -r $STREAMEYE_CONF || exit 1 - -watch() { - count=0 - while true; do - sleep 5 - if ! ps aux | grep raspimjpeg.py | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - fi - done -} - -function start() { - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -n "$pid" ]; then - return - fi - - raspimjpeg_opts="" - while read line; do - if echo "$line" | grep false &>/dev/null; then - continue - fi - if echo "$line" | grep true &>/dev/null; then - line=$(echo $line | cut -d ' ' -f 1) - fi - raspimjpeg_opts="$raspimjpeg_opts --$line" - done < $RASPIMJPEG_CONF - - source $STREAMEYE_CONF - streameye_opts="-p $PORT" - if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then - streameye_opts="$streameye_opts -a basic -c $CREDENTIALS" - fi - - if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then - raspimjpeg_opts="$raspimjpeg_opts -d" - streameye_opts="$streameye_opts -d" - fi - - raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG & -} - -function stop() { - # stop the streameye background watch process - ps | grep streameye.sh | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - - # stop the raspimjpeg process - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -z "$pid" ]; then - return - fi - - kill -HUP "$pid" &>/dev/null - count=0 - while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do - sleep 1 - count=$(($count + 1)) - done - kill -KILL "$pid" &>/dev/null || true -} - -case "$1" in - start) - start - watch & - ;; - - stop) - stop - ;; - - restart) - stop - start - watch & - ;; - - *) - echo $"Usage: $0 {start|stop|restart}" - exit 1 -esac - diff --git a/board/raspberrypi3/motioneye-modules/boardctl.py b/board/raspberrypi3/motioneye-modules/boardctl.py deleted file mode 100644 index 9fdfa06e54..0000000000 --- a/board/raspberrypi3/motioneye-modules/boardctl.py +++ /dev/null @@ -1,238 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import logging -import os.path - -from config import additional_config - -import streameyectl - - -CONFIG_TXT = '/boot/config.txt' -MONITOR = '/data/etc/monitor_1' - -MONITOR_SCRIPT = '''#!/bin/bash - -net_tmp=/tmp/netspeed.tmp -temp=$(($(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)) -load=$(cat /proc/loadavg | cut -d ' ' -f 2) -recv=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 3 | tail -n +3 | awk '{s+=$1} END {print s}') -send=$(cat /proc/net/dev | grep -v 'lo:' | tr -s ' ' | cut -d ' ' -f 11 | tail -n +3 | awk '{s+=$1} END {print s}') -total=$(($recv + $send)) - -if [ -e $net_tmp ]; then - prev_total=$(cat $net_tmp) - speed=$(($total - $prev_total)) -else - speed=0 -fi - -echo $total > $net_tmp -speed=$(($speed / 1024)) - -echo -n "$temp°|$load|${speed}kB/s" -''' - -OVERCLOCK = { - 700: '700|250|400|0', - 800: '800|250|400|0', - 900: '900|250|450|0', - 950: '950|250|450|0', - 1000: '1000|500|600|6', - 1001: '1001|500|500|2' -} - -def _get_board_settings(): - gpu_mem = 128 - camera_led = True - arm_freq = 700 - - if os.path.exists(CONFIG_TXT): - logging.debug('reading board settings from %s' % CONFIG_TXT) - - with open(CONFIG_TXT) as f: - for line in f: - line = line.strip() - if not line or line.startswith('#'): - continue - - parts = line.split('=', 1) - if len(parts) != 2: - continue - - name, value = parts - name = name.strip() - value = value.strip() - - if name == 'gpu_mem': - gpu_mem = int(value) - - elif name == 'arm_freq': - arm_freq = int(value) - - elif name == 'disable_camera_led': - camera_led = value == '0' - - - s = { - 'gpuMem': gpu_mem, - 'cameraLed': camera_led - } - - logging.debug('board settings: gpu_mem=%(gpuMem)s, camera_led=%(cameraLed)s' % s) - - return s - - -def _set_board_settings(s): - s.setdefault('gpuMem', 128) - s.setdefault('cameraLed', True) - - old_settings = _get_board_settings() - if s == old_settings: - return # nothing has changed - - seen = set() - - logging.debug('writing board settings to %s: ' % CONFIG_TXT + - 'gpu_mem=%(gpuMem)s, camera_led=%(cameraLed)s' % s) - - lines = [] - if os.path.exists(CONFIG_TXT): - with open(CONFIG_TXT) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - line = line.strip('#') - - try: - name, _ = line.split('=', 1) - name = name.strip() - - except: - continue - - seen.add(name) - - if name == 'gpu_mem': - lines[i] = '%s=%s' % (name, s['gpuMem']) - - elif name == 'disable_camera_led': - lines[i] = 'disable_camera_led=%s' % ['1', '0'][s['cameraLed']] - - if 'gpu_mem' not in seen: - lines.append('gpu_mem=%s' % s['gpuMem']) - - if 'disable_camera_led' not in seen: - lines.append('disable_camera_led=%s' % ['1', '0'][s['cameraLed']]) - - logging.debug('remounting /boot read-write') - if os.system('mount -o remount,rw /boot'): - logging.error('failed to remount /boot read-write') - - with open(CONFIG_TXT, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_sys_mon(): - return os.access(MONITOR, os.X_OK) - - -def _set_sys_mon(sys_mon): - if sys_mon: - if os.access(MONITOR, os.X_OK): - pass - - else: - if os.path.exists(MONITOR): - os.system('chmod +x %s' % MONITOR) - - else: - with open(MONITOR, 'w') as f: - f.write(MONITOR_SCRIPT) - - os.system('chmod +x %s' % MONITOR) - - else: - if os.access(MONITOR, os.X_OK): - os.system('chmod -x %s' % MONITOR) - - -@additional_config -def boardSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def gpuMem(): - return { - 'label': 'GPU Memory', - 'description': 'set the amount of memory reserved for the GPU (choose at least 96MB if you use the CSI camera board)', - 'type': 'number', - 'min': '16', - 'max': '944', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def cameraLed(): - return { - 'label': 'Enable CSI Camera Led', - 'description': 'control the led on the CSI camera board', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_board_settings, - 'set': _set_board_settings, - 'get_set_dict': True - } - - -@additional_config -def sysMon(): - return { - 'label': 'Enable System Monitoring', - 'description': 'when this is enabled, system monitoring info will be overlaid on top of the first camera frame', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': False, - 'get': _get_sys_mon, - 'set': _set_sys_mon - } - diff --git a/board/raspberrypi3/motioneye-modules/streameyectl.py b/board/raspberrypi3/motioneye-modules/streameyectl.py deleted file mode 100644 index 5f751332f4..0000000000 --- a/board/raspberrypi3/motioneye-modules/streameyectl.py +++ /dev/null @@ -1,1172 +0,0 @@ - -# Copyright (c) 2015 Calin Crisan -# This file is part of motionEyeOS. -# -# motionEyeOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import config -import hashlib -import logging -import os.path -import re - -from tornado.ioloop import IOLoop - -import settings - -from config import additional_config - - -MOTIONEYE_CONF = '/data/etc/motioneye.conf' -RASPIMJPEG_CONF = '/data/etc/raspimjpeg.conf' -STREAMEYE_CONF = '/data/etc/streameye.conf' - -EXPOSURE_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('night', 'Night'), - ('nightpreview', 'Night Preview'), - ('backlight', 'Backlight'), - ('spotlight', 'Spotlight'), - ('sports', 'Sports'), - ('snow', 'Snow'), - ('beach', 'Beach'), - ('verylong', 'Very Long'), - ('fixedfps', 'Fixed FPS'), - ('antishake', 'Antishake'), - ('fireworks', 'Fireworks') -] - -AWB_CHOICES = [ - ('off', 'Off'), - ('auto', 'Auto'), - ('sunlight', 'Sunlight'), - ('cloudy', 'Cloudy'), - ('shade', 'Shade'), - ('tungsten', 'Tungsten'), - ('fluorescent', 'Fluorescent'), - ('incandescent', 'Incandescent'), - ('flash', 'Flash'), - ('horizon', 'Horizon') -] - -METERING_CHOICES = [ - ('average', 'Average'), - ('spot', 'Spot'), - ('backlit', 'Backlit'), - ('matrix', 'Matrix') -] - -DRC_CHOICES = [ - ('off', 'Off'), - ('low', 'Low'), - ('medium', 'Medium'), - ('high', 'High') -] - -IMXFX_CHOICES = [ - ('none', 'None'), - ('negative', 'Negative'), - ('solarize', 'Solarize'), - ('sketch', 'Sketch'), - ('denoise', 'Denoise'), - ('emboss', 'Emboss'), - ('oilpaint', 'Oilpaint'), - ('hatch', 'Hatch'), - ('gpen', 'G Pen'), - ('pastel', 'Pastel'), - ('watercolor', 'Water Color'), - ('film', 'Film'), - ('blur', 'Blur'), - ('saturation', 'Saturation'), - ('colorswap', 'Color Swap'), - ('washedout', 'Washed Out'), - ('posterise', 'Posterize'), - ('colorpoint', 'Color Point'), - ('colorbalance', 'Color Balance'), - ('cartoon', 'Cartoon'), - ('deinterlace1', 'Deinterlace 1'), - ('deinterlace2', 'Deinterlace 2') -] - -RESOLUTION_CHOICES = [ - ('320x200', '320x200'), - ('320x240', '320x240'), - ('640x480', '640x480'), - ('800x480', '800x480'), - ('800x600', '800x600'), - ('1024x576', '1024x576'), - ('1024x768', '1024x768'), - ('1280x720', '1280x720'), - ('1280x800', '1280x800'), - ('1280x960', '1280x960'), - ('1280x1024', '1280x1024'), - ('1296x972', '1296x972'), - ('1440x960', '1440x960'), - ('1440x1024', '1440x1024'), - ('1600x1200', '1600x1200'), - ('1640x922', '1640x922'), - ('1640x1232', '1640x1232'), - ('1920x1080', '1920x1080'), - ('2592x1944', '2592x1944'), - ('3280x2464', '3280x2464') -] - -ROTATION_CHOICES = [ - ('0', '0°'), - ('90', '90°'), - ('180', '180°'), - ('270', '270°') -] - -AUTH_CHOICES = [ - ('disabled', 'Disabled'), - ('basic', 'Basic'), -] - -_streameye_enabled = None - - -def _get_streameye_enabled(): - global _streameye_enabled - - if _streameye_enabled is not None: - return _streameye_enabled - - camera_ids = config.get_camera_ids(filter_valid=False) # filter_valid prevents infinte recursion - if len(camera_ids) != 1: - _streameye_enabled = False - return False - - camera_config = config.get_camera(camera_ids[0], as_lines=True) # as_lines prevents infinte recursion - camera_config = config._conf_to_dict(camera_config) - if camera_config.get('@proto') != 'mjpeg': - _streameye_enabled = False - return False - if '127.0.0.1:' not in camera_config.get('@url', ''): - _streameye_enabled = False - return False - - _streameye_enabled = True - return True - - -def _set_streameye_enabled_deferred(enabled): - was_enabled = _get_streameye_enabled() - if enabled and not was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, True) - - elif not enabled and was_enabled: - io_loop = IOLoop.instance() - io_loop.add_callback(_set_streameye_enabled, False) - - if enabled: - # this will force updating streameye settings whenever the surveillance credentials are changed - streameye_settings = _get_streameye_settings(1) - _set_streameye_settings(1, streameye_settings) - - -def _set_streameye_enabled(enabled): - global _streameye_enabled - - if enabled: - logging.debug('removing all cameras from cache') - config._camera_config_cache = {} - config._camera_ids_cache = [] - - logging.debug('disabling all cameras in motion.conf') - cmd = 'sed -r -i "s/^thread (.*)/#thread \\1/" /data/etc/motion.conf &>/dev/null' - if os.system(cmd): - logging.error('failed to disable cameras in motion.conf') - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name + '.bak')) - - logging.debug('adding simple mjpeg camera') - - streameye_settings = _get_streameye_settings(1) - main_config = config.get_main() - - device_details = { - 'proto': 'mjpeg', - 'host': '127.0.0.1', - 'port': streameye_settings['sePort'], - 'username': '', - 'password': '', - 'scheme': 'http', - 'path': '/' - } - - if streameye_settings['seAuthMode'] == 'basic': - device_details['username'] = main_config['@normal_username'] - device_details['password'] = main_config['@normal_password'] - - _streameye_enabled = True - config._additional_structure_cache = {} - camera_config = config.add_camera(device_details) - - # call set_camera again so that the streamEye-related defaults are saved - config.set_camera(camera_config['@id'], camera_config) - - _set_motioneye_add_remove_cameras(False) - - else: # disabled - logging.debug('removing simple mjpeg camera') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - if camera_config.get('@proto') == 'mjpeg': - config.rem_camera(camera_id) - - logging.debug('renaming thread files') - for name in os.listdir(settings.CONF_PATH): - if re.match('^thread-\d+.conf.bak$', name): - os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name[:-4])) - - _streameye_enabled = False - config.invalidate() - - logging.debug('enabling all cameras') - for camera_id in config.get_camera_ids(): - camera_config = config.get_camera(camera_id) - camera_config['@enabled'] = True - config.set_camera(camera_id, camera_config) - - _set_motioneye_add_remove_cameras(True) - - -def _set_motioneye_add_remove_cameras(enabled): - logging.debug('%s motionEye add/remove cameras' % ['disabling', 'enabling'][enabled]) - - lines = [] - found = False - if os.path.exists(MOTIONEYE_CONF): - with open(MOTIONEYE_CONF) as f: - lines = f.readlines() - - for i, line in enumerate(lines): - line = line.strip() - if not line: - continue - - try: - name, _ = line.split(' ', 2) - - except: - continue - - name = name.replace('_', '-') - - if name == 'add-remove-cameras': - lines[i] = 'add-remove-cameras %s' % str(enabled).lower() - found = True - - if not found: - lines.append('add-remove-cameras %s' % str(enabled).lower()) - - with open(MOTIONEYE_CONF, 'w') as f: - for line in lines: - if not line.strip(): - continue - if not line.endswith('\n'): - line += '\n' - f.write(line) - - -def _get_raspimjpeg_settings(camera_id): - s = { - 'preview': False, - 'brightness': 50, - 'contrast': 0, - 'saturation': 0, - 'sharpness': 0, - 'iso': 400, - 'ev': 0, - 'shutter': 0, - 'exposure': 'auto', - 'awb': 'auto', - 'metering': 'average', - 'drc': 'off', - 'vstab': False, - 'denoise': False, - 'imxfx': 'none', - 'width': 640, - 'height': 480, - 'rotation': 0, - 'vflip': False, - 'hflip': False, - 'framerate': 15, - 'quality': 25, - 'zoomx': 0, - 'zoomy': 0, - 'zoomw': 100, - 'zoomh': 100 - } - - if os.path.exists(RASPIMJPEG_CONF): - logging.debug('reading raspimjpeg settings from %s' % RASPIMJPEG_CONF) - - with open(RASPIMJPEG_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - try: - name, value = line.split(' ', 1) - - except: - continue - - name = name.replace('_', '-') - - try: - value = int(value) - - except: - pass - - if value == 'false': - value = False - - elif value == 'true': - value = True - - if name == 'zoom': - try: - parts = value.split(',') - s['zoomx'] = int(float(parts[0]) * 100) - s['zoomy'] = int(float(parts[1]) * 100) - s['zoomw'] = int(float(parts[2]) * 100) - s['zoomh'] = int(float(parts[3]) * 100) - - except: - logging.error('failed to parse zoom setting "%s"' % value) - - continue - - s[name] = value - - s['contrast'] = (s['contrast'] + 100) / 2 - s['saturation'] = (s['saturation'] + 100) / 2 - s['sharpness'] = (s['sharpness'] + 100) / 2 - - s['resolution'] = '%sx%s' % (s.pop('width'), s.pop('height')) - - s = dict(('se' + n[0].upper() + n[1:], v) for (n, v) in s.items()) - - return s - - -def _set_raspimjpeg_settings(camera_id, s): - s = dict((n[2].lower() + n[3:], v) for (n, v) in s.items()) - - s['width'] = int(s['resolution'].split('x')[0]) - s['height'] = int(s.pop('resolution').split('x')[1]) - - s['zoom'] = '%.2f,%.2f,%.2f,%.2f' % ( - s.pop('zoomx') / 100.0, s.pop('zoomy') / 100.0, - s.pop('zoomw') / 100.0, s.pop('zoomh') / 100.0) - - s['contrast'] = s['contrast'] * 2 - 100 - s['saturation'] = s['saturation'] * 2 - 100 - s['sharpness'] = s['sharpness'] * 2 - 100 - - logging.debug('writing raspimjpeg settings to %s' % RASPIMJPEG_CONF) - - lines = [] - for name, value in sorted(s.items(), key=lambda i: i[0]): - if isinstance(value, bool): - value = str(value).lower() - - line = '%s %s\n' % (name, value) - lines.append(line) - - with open(RASPIMJPEG_CONF, 'w') as f: - for line in lines: - f.write(line) - - -def _get_streameye_settings(camera_id): - s = { - 'seAuthMode': 'disabled', - 'sePort': 8081, - } - - if os.path.exists(STREAMEYE_CONF): - logging.debug('reading streameye settings from %s' % STREAMEYE_CONF) - - with open(STREAMEYE_CONF) as f: - for line in f: - line = line.strip() - if not line: - continue - - m = re.findall('PORT="?(\d+)"?', line) - if m: - s['sePort'] = int(m[0]) - continue - - m = re.findall('AUTH="?(\w+)"?', line) - if m: - s['seAuthMode'] = m[0] - - return s - - -def _set_streameye_settings(camera_id, s): - s = dict(s) - s.setdefault('sePort', 8081) - s.setdefault('seAuthMode', 'disabled') - - main_config = config.get_main() - username = main_config['@normal_username'] - password = main_config['@normal_password'] - realm = 'motionEyeOS' - - logging.debug('writing streameye settings to %s' % STREAMEYE_CONF) - - lines = [ - 'PORT="%s"' % s['sePort'], - 'AUTH="%s"' % s['seAuthMode'], - 'CREDENTIALS="%s:%s:%s"' % (username, password, realm) - ] - - with open(STREAMEYE_CONF, 'w') as f: - for line in lines: - f.write(line + '\n') - - if 1 in config.get_camera_ids(): - # a workaround to update the camera username and password - # since we cannot call set_camera() from here - if s['seAuthMode'] == 'basic': - url = 'http://%s:%s@127.0.0.1:%s/' % (username, password, s['sePort']) - - else: - url = 'http://127.0.0.1:%s/' % s['sePort'] - - if 1 in config._camera_config_cache: - logging.debug('updating streaming authentication in config cache') - config._camera_config_cache[1]['@url'] = url - - lines = config.get_camera(1, as_lines=True) - for i, line in enumerate(lines): - if line.startswith('# @url'): - lines[i] = '# @url %s' % url - - config_file = os.path.join(settings.CONF_PATH, config._CAMERA_CONFIG_FILE_NAME % {'id': 1}) - logging.debug('updating streaming authentication in camera config file %s' % config_file) - with open(config_file, 'w') as f: - for line in lines: - f.write(line + '\n') - - logging.debug('restarting streameye') - if os.system('streameye.sh restart'): - logging.error('streameye restart failed') - - -# make streameye-related log files downloadable - -if _get_streameye_enabled(): - def _add_log_handlers(): - import handlers - handlers.LogHandler.LOGS['streameye'] = (os.path.join(settings.LOG_PATH, 'streameye.log'), 'streameye.log') - handlers.LogHandler.LOGS['raspimjpeg'] = (os.path.join(settings.LOG_PATH, 'raspimjpeg.log'), 'raspimjpeg.log') - - # handlers.LogHandler is not yet available - # at the time streameyectl is imported - io_loop = IOLoop.instance() - io_loop.add_callback(_add_log_handlers) - - @additional_config - def streamEyeLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'streameye.log', - } - - @additional_config - def raspiMjpegLog(): - return { - 'type': 'html', - 'section': 'expertSettings', - 'advanced': True, - 'get': lambda: 'raspimjpeg.log', - } - - -@additional_config -def streamEyeMainSeparator(): - return { - 'type': 'separator', - 'section': 'expertSettings', - 'advanced': True - } - - -@additional_config -def streamEye(): - return { - 'label': 'Fast Network Camera', - 'description': 'Enabling this option will turn your Raspberry PI into a simple and fast MJPEG network camera, ' + - 'disabling motion detection, media files and all other advanced features (works only with the CSI camera)', - 'type': 'bool', - 'section': 'expertSettings', - 'advanced': True, - 'reboot': True, - 'get': _get_streameye_enabled, - 'set': _set_streameye_enabled_deferred, - } - - -@additional_config -def streamEyeCameraSeparator1(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seBrightness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Brightness', - 'description': 'sets a desired brightness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seContrast(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Contrast', - 'description': 'sets a desired contrast level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSaturation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Saturation', - 'description': 'sets a desired saturation level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seSharpness(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Sharpness', - 'description': 'sets a desired sharpness level for this camera', - 'type': 'range', - 'min': 0, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - - -@additional_config -def streamEyeCameraSeparator2(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seResolution(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Resolution', - 'description': 'the video resolution (larger values produce better quality but require more CPU power, larger storage space and bandwidth)', - 'type': 'choices', - 'choices': RESOLUTION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seRotation(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Rotation', - 'description': 'use this to rotate the captured image, if your camera is not positioned correctly', - 'type': 'choices', - 'choices': ROTATION_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Vertically', - 'description': 'enable this to flip the captured image vertically', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seHflip(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Flip Horizontally', - 'description': 'enable this to flip the captured image horizontally', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seFramerate(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Frame Rate', - 'description': 'sets the number of frames captured by the camera every second (higher values produce smoother videos but require more CPU power, larger storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 30, - 'snap': 0, - 'ticks': "1|5|10|15|20|25|30", - 'decimals': 0, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seQuality(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Quality', - 'description': 'sets the JPEG image quality (higher values produce a better image quality but require more storage space and bandwidth)', - 'type': 'range', - 'min': 1, - 'max': 100, - 'snap': 2, - 'ticks': '1|25|50|75|100', - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom X', - 'description': 'sets the horizontal zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomy(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Y', - 'description': 'sets the vertical zoom offset', - 'type': 'range', - 'min': 0, - 'max': 80, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomw(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Width', - 'description': 'sets the zoom width', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seZoomh(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Zoom Height', - 'description': 'sets the zoom height', - 'type': 'range', - 'min': 20, - 'max': 100, - 'snap': 2, - 'ticksnum': 5, - 'decimals': 0, - 'unit': '%', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePreview(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'HDMI Preview', - 'description': 'enable this if you want to see the preview on an HDMI-connected monitor', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator3(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seIso(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'ISO', - 'description': 'sets a desired ISO level for this camera', - 'type': 'range', - 'min': 100, - 'max': 800, - 'snap': 1, - 'ticksnum': 8, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seShutter(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Shutter Speed', - 'description': 'sets a desired shutter speed for this camera', - 'type': 'number', - 'min': 0, - 'max': 6000000, - 'unit': 'microseconds', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def streamEyeCameraSeparator4(): - return { - 'type': 'separator', - 'section': 'device', - 'camera': True, - 'advanced': True - } - - -@additional_config -def seExposure(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Mode', - 'description': 'sets a desired exposure mode for this camera', - 'type': 'choices', - 'choices': EXPOSURE_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seEv(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Exposure Compensation', - 'description': 'sets a desired exposure compensation for this camera', - 'type': 'range', - 'min': -25, - 'max': 25, - 'snap': 1, - 'ticksnum': 11, - 'decimals': 0, - 'unit': '', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seAwb(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Automatic White Balance', - 'description': 'sets a desired automatic white balance mode for this camera', - 'type': 'choices', - 'choices': AWB_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seMetering(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Metering Mode', - 'description': 'sets a desired metering mode for this camera', - 'type': 'choices', - 'choices': METERING_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDrc(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Dynamic Range Compensation', - 'description': 'sets a desired dynamic range compensation level for this camera', - 'type': 'choices', - 'choices': DRC_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seVstab(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Video Stabilization', - 'description': 'enables or disables video stabilization for this camera', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seDenoise(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Denoise', - 'description': 'enables image denoising', - 'type': 'bool', - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def seImxfx(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Image Effect', - 'description': 'sets a desired image effect for this camera', - 'type': 'choices', - 'choices': IMXFX_CHOICES, - 'section': 'device', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_raspimjpeg_settings, - 'set': _set_raspimjpeg_settings, - 'get_set_dict': True - } - - -@additional_config -def sePort(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Streaming Port', - 'description': 'sets the TCP port on which the webcam streaming server listens', - 'type': 'number', - 'min': 1024, - 'max': 65535, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - - -@additional_config -def seAuthMode(): - if not _get_streameye_enabled(): - return None - - return { - 'label': 'Authentication Mode', - 'description': 'the authentication mode to use when accessing the stream (use Basic instead of Digest if you encounter issues with third party apps)', - 'type': 'choices', - 'choices': AUTH_CHOICES, - 'section': 'streaming', - 'advanced': True, - 'camera': True, - 'required': True, - 'get': _get_streameye_settings, - 'set': _set_streameye_settings, - 'get_set_dict': True - } - diff --git a/board/raspberrypi3/overlay/etc/init.d/S84streameye b/board/raspberrypi3/overlay/etc/init.d/S84streameye deleted file mode 100755 index 81e2e2c896..0000000000 --- a/board/raspberrypi3/overlay/etc/init.d/S84streameye +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -motioneye_conf_dir="/data/etc/" - -test -n "$os_version" || source /etc/init.d/base - -enabled() { - test $(ls -1 $motioneye_conf_dir/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1 - - grep '# @proto mjpeg' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - grep -E '# @url http://(.*)127.0.0.1:' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1 - - return 0 -} - -enabled || exit 0 - -start() { - msg_begin "Starting streameye" - streameye.sh start - test $? == 0 && msg_done || msg_fail -} - -stop() { - msg_begin "Stopping streameye" - streameye.sh stop - test $? == 0 && msg_done || msg_fail -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - restart) - stop - start - ;; - - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/raspberrypi3/overlay/etc/modules b/board/raspberrypi3/overlay/etc/modules deleted file mode 100644 index 2990e0b8e0..0000000000 --- a/board/raspberrypi3/overlay/etc/modules +++ /dev/null @@ -1,3 +0,0 @@ -bcm2835-v4l2 max_video_width=2592 max_video_height=1944 -bcm2835-wdt - diff --git a/board/raspberrypi3/overlay/usr/bin/streameye.sh b/board/raspberrypi3/overlay/usr/bin/streameye.sh deleted file mode 100755 index 8ab060182b..0000000000 --- a/board/raspberrypi3/overlay/usr/bin/streameye.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -RASPIMJPEG_CONF=/data/etc/raspimjpeg.conf -RASPIMJPEG_LOG=/var/log/raspimjpeg.log -MOTIONEYE_CONF=/data/etc/motioneye.conf -STREAMEYE_CONF=/data/etc/streameye.conf -STREAMEYE_LOG=/var/log/streameye.log - -test -r $RASPIMJPEG_CONF || exit 1 -test -r $STREAMEYE_CONF || exit 1 - -watch() { - count=0 - while true; do - sleep 5 - if ! ps aux | grep raspimjpeg.py | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - fi - done -} - -function start() { - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -n "$pid" ]; then - return - fi - - raspimjpeg_opts="" - while read line; do - if echo "$line" | grep false &>/dev/null; then - continue - fi - if echo "$line" | grep true &>/dev/null; then - line=$(echo $line | cut -d ' ' -f 1) - fi - raspimjpeg_opts="$raspimjpeg_opts --$line" - done < $RASPIMJPEG_CONF - - source $STREAMEYE_CONF - streameye_opts="-p $PORT" - if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then - streameye_opts="$streameye_opts -a basic -c $CREDENTIALS" - fi - - if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then - raspimjpeg_opts="$raspimjpeg_opts -d" - streameye_opts="$streameye_opts -d" - fi - - raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG & -} - -function stop() { - # stop the streameye background watch process - ps | grep streameye.sh | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - - # stop the raspimjpeg process - pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) - if [ -z "$pid" ]; then - return - fi - - kill -HUP "$pid" &>/dev/null - count=0 - while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do - sleep 1 - count=$(($count + 1)) - done - kill -KILL "$pid" &>/dev/null || true -} - -case "$1" in - start) - start - watch & - ;; - - stop) - stop - ;; - - restart) - stop - start - watch & - ;; - - *) - echo $"Usage: $0 {start|stop|restart}" - exit 1 -esac -