From 6e075c82b2465a6550dabf678b385e306c40a86c Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 23 Nov 2013 10:39:20 +0200 Subject: [PATCH] implemented image request flooding protection --- README.md | 4 ++-- raspicam/motion | 16 +++++++++++++++- static/js/main.js | 9 +++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6fa566d..a958d30 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ * PIL * motion * ffmpeg - * v4l2-utils + * v4l-utils On a debian-based system you could run: - apt-get install python-tornado python-jinja2 python-imaging motion ffmpeg v4l2-utils + apt-get install python-tornado python-jinja2 python-imaging motion ffmpeg v4l-utils ## Browser Compatibility ## diff --git a/raspicam/motion b/raspicam/motion index de31555..ef21046 100755 --- a/raspicam/motion +++ b/raspicam/motion @@ -6,6 +6,16 @@ MOTION_BIN=/usr/bin/motion UV4L_BIN=/usr/bin/uv4l JPEG_QUALITY=85 +ARGS="$*" + +function config_full_path() { + dir="$1" + read file + if [ "${file:0:1}" != "/" ]; then + file="$dir/$file" + fi + echo "$file" +} function list_config_files() { prev_arg="" @@ -20,7 +30,7 @@ function list_config_files() { if [ -r "$config_file" ];then echo "$config_file" - cat motion.conf | grep thread | cut -d ' ' -f 2 + cat motion.conf | grep thread | cut -d ' ' -f 2 | config_full_path $(dirname "$config_file") fi } @@ -32,6 +42,9 @@ function find_resolution() { w=$(cat "$file" | grep width | cut -d ' ' -f 2) h=$(cat "$file" | grep height | cut -d ' ' -f 2) if [ -n "$w" ] && [ -n "$h" ]; then + width=$w + height=$h + break fi done @@ -50,3 +63,4 @@ ${UV4L_BIN} --driver raspicam --auto-video_nr --extension-presence 1 --sched-rr # start motion binary with preloaded .so export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so exec ${MOTION_BIN} $* + diff --git a/static/js/main.js b/static/js/main.js index 23b8fcd..438c55e 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1657,12 +1657,16 @@ function addCameraFrameUi(cameraId, cameraName, framerate) { /* error and load handlers */ cameraImg.error(function () { this.error = true; + this.loading = false; + cameraImg.addClass('error'); cameraImg.height(Math.round(cameraImg.width() * 0.75)); cameraPlaceholder.css('opacity', 1); }); cameraImg.load(function () { this.error = false; + this.loading = false; + cameraImg.removeClass('error'); cameraImg.css('height', ''); cameraPlaceholder.css('opacity', 0); @@ -1829,12 +1833,17 @@ function refreshCameraFrames() { } function refreshCameraFrame(cameraId, img, fast) { + if (img.loading) { + return; /* still loading the previous image */ + } + var timestamp = new Date().getTime(); if (!fast) { timestamp /= 500; } timestamp = Math.round(timestamp); img.src = '/picture/' + cameraId + '/current/?_=' + timestamp; + img.loading = true; } var cameraFrames; -- 2.39.5