]> www.vanbest.org Git - motioneye-debian/commitdiff
minor effective framerate improvements
authorCalin Crisan <ccrisan@gmail.com>
Sun, 12 Apr 2015 11:52:59 +0000 (14:52 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 12 Apr 2015 12:09:31 +0000 (15:09 +0300)
settings_default.py
static/js/frame.js
static/js/main.js

index 21c42c95afc349056033a861de63b69366e16fc3..69b3b27ff122cd09fe65e421f4aca13b0c0f435c 100644 (file)
@@ -24,7 +24,7 @@ LOG_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'log'))
 MEDIA_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'media'))
 
 # path to motion binary (automatically detected if not set)
-MOTION_BINARY = None 
+MOTION_BINARY = None
 
 # set to logging.DEBUG for verbose output
 LOG_LEVEL = logging.INFO
index b403e860ee5ae920cea940b0bb24a06c9d230faf..3d77c514859e7aca131efce8d91ee75541c7a03f 100644 (file)
@@ -46,11 +46,17 @@ function setupCameraFrame() {
         cameraPlaceholder.css('opacity', 0);
         cameraProgress.removeClass('visible');
         
-        if (getCookie('motion_detected_' + cameraId) == 'true') {
-            cameraFrameDiv.addClass('motion-detected');
-        }
-        else {
-            cameraFrameDiv.removeClass('motion-detected');
+        /* there's no point in looking for a cookie update more often than once every second */
+        var now = new Date().getTime();
+        if (!this.lastCookieTime || now - this.lastCookieTime > 1000) {
+            if (getCookie('motion_detected_' + cameraId) == 'true') {
+                cameraFrameDiv.addClass('motion-detected');
+            }
+            else {
+                cameraFrameDiv.removeClass('motion-detected');
+            }
+            
+            this.lastCookieTime = now;
         }
 
         if (this.naturalWidth / this.naturalHeight > body.width() / body.height()) {
@@ -72,8 +78,13 @@ function refreshCameraFrame() {
     var img = $cameraFrame.find('img.camera')[0];
     var cameraId = cameraFrame.id.substring(6);
     
-    /* limit the refresh rate to 20 fps */
-    var count = Math.max(1, 1 / cameraFrame.streamingFramerate * 1000 / refreshInterval);
+    /* at a refresh interval of 50ms, the refresh rate is limited to 20 fps */
+    var count = 1000 / (refreshInterval * cameraFrame.streamingFramerate);
+    if (count <= 2) {
+        /* skipping frames (showing the same frame twice) at this rate won't be visible,
+         * while the effective framerate will be as close as possible to the motion's one */
+        count -= 1;
+    }
     
     if (img.error) {
         /* in case of error, decrease the refresh rate to 1 fps */
index aeaf8a08b153d8de0a29bfee09c1fa78e11554fb..9359c694c2c4b901b7932b918485da69b5715221 100644 (file)
@@ -3426,11 +3426,17 @@ function addCameraFrameUi(cameraConfig) {
         cameraPlaceholder.css('opacity', 0);
         cameraProgress.removeClass('visible');
         
-        if (getCookie('motion_detected_' + cameraId) == 'true') {
-            cameraFrameDiv.addClass('motion-detected');
-        }
-        else {
-            cameraFrameDiv.removeClass('motion-detected');
+        /* there's no point in looking for a cookie update more often than once every second */
+        var now = new Date().getTime();
+        if (!this.lastCookieTime || now - this.lastCookieTime > 1000) {
+            if (getCookie('motion_detected_' + cameraId) == 'true') {
+                cameraFrameDiv.addClass('motion-detected');
+            }
+            else {
+                cameraFrameDiv.removeClass('motion-detected');
+            }
+            
+            this.lastCookieTime = now;
         }
 
         if (fullScreenCameraId) {
@@ -3504,7 +3510,7 @@ function doConfigureCamera(cameraId) {
 }
 
 function doFullScreenCamera(cameraId) {
-    if (inProgress || refreshCameraFrames[cameraId]) {
+    if (inProgress || refreshDisabled[cameraId]) {
         return;
     }
     
@@ -3576,7 +3582,7 @@ function refreshCameraFrames() {
         if (img.loading) {
             img.loading++; /* increases each time the camera would refresh but is still loading */
             
-            if (img.loading > 2 * 1000 / refreshInterval) { /* limits the retry at one every two seconds */
+            if (img.loading > 2 * 1000 / refreshInterval) { /* limits the retries to one every two seconds */
                 img.loading = 0;
             }
             else {
@@ -3606,12 +3612,21 @@ function refreshCameraFrames() {
     }
     
     cameraFrames.each(function () {
-        /* limit the refresh rate to 20 fps */
-        var count = Math.max(0, 1 / this.config['streaming_framerate'] * 1000 / refreshInterval);
+        if (!this.img) {
+            this.img = $(this).find('img.camera')[0];
+        }
+        
+        /* at a refresh interval of 50ms, the refresh rate is limited to 20 fps */
+        var count = 1000 / (refreshInterval * this.config['streaming_framerate']);
         var serverSideResize = this.config['streaming_server_resize'];
-        var img = $(this).find('img.camera')[0];
         
-        if (img.error) {
+        if (count <= 2) {
+            /* skipping frames (showing the same frame twice) at this rate won't be visible,
+             * while the effective framerate will be as close as possible to the motion's one */
+            count -= 1;
+        }
+        
+        if (this.img.error) {
             /* in case of error, decrease the refresh rate to 1 fps */
             count = 1000 / refreshInterval;
         }
@@ -3621,7 +3636,7 @@ function refreshCameraFrames() {
         }
         else {
             var cameraId = this.id.substring(6);
-            refreshCameraFrame(cameraId, img, serverSideResize);
+            refreshCameraFrame(cameraId, this.img, serverSideResize);
             
             this.refreshDivider = 0;
         }