]> www.vanbest.org Git - motioneye-debian/commitdiff
current picture cache fix; removed the secondary remote picture cache
authorCalin Crisan <ccrisan@gmail.com>
Sun, 1 Dec 2013 14:05:10 +0000 (16:05 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 1 Dec 2013 14:05:10 +0000 (16:05 +0200)
src/handlers.py
src/mediafiles.py
src/remote.py
static/js/ui.js

index ef4daed97a9a5c6bebe8b646739f5fa43bc82eb0..dbb025e2c7d0af06915ab5f25e443e7e4d234e81 100644 (file)
@@ -544,8 +544,11 @@ class PictureHandler(BaseHandler):
         sequence = self.get_argument('seq', None)
         if sequence:
             sequence = int(sequence)
-            
-        picture = sequence and mediafiles.get_picture_cache(camera_id, sequence) or None
+        
+        width = self.get_argument('width', None)
+        height = self.get_argument('height', None)
+        
+        picture = sequence and mediafiles.get_picture_cache(camera_id, sequence, width) or None
         
         if picture is not None:
             return self.finish(picture)
@@ -553,18 +556,18 @@ class PictureHandler(BaseHandler):
         camera_config = config.get_camera(camera_id)
         if camera_config['@proto'] == 'v4l2':
             picture = mediafiles.get_current_picture(camera_config,
-                    width=self.get_argument('width', None),
-                    height=self.get_argument('height', None))
+                    width=width,
+                    height=height)
             
             if sequence and picture:
-                mediafiles.set_picture_cache(camera_id, sequence, picture)
+                mediafiles.set_picture_cache(camera_id, sequence, width, picture)
 
             self.finish(picture)
         
         else:
             def on_response(picture):
                 if sequence and picture:
-                    mediafiles.set_picture_cache(camera_id, sequence, picture)
+                    mediafiles.set_picture_cache(camera_id, sequence, width, picture)
                 
                 self.finish(picture)
             
@@ -575,8 +578,8 @@ class PictureHandler(BaseHandler):
                     camera_config['@password'],
                     camera_config['@remote_camera_id'],
                     on_response,
-                    width=self.get_argument('width', None),
-                    height=self.get_argument('height', None))
+                    width=width,
+                    height=height)
 
     @BaseHandler.auth()
     def list(self, camera_id):
index ab3ceb8aa56df314f25a5478b1e012cefc4236ff..e7d45ed26fcbcf6c3bc4821753c3bdb4b1b0736b 100644 (file)
@@ -33,7 +33,7 @@ _PICTURE_EXTS = ['.jpg']
 _MOVIE_EXTS = ['.avi', '.mp4']
 
 # a dictionary indexed by camera_id containing
-# tuples of (sequence, content)
+# tuples of (sequence, width, content)
 _current_pictures_cache = {}
 
 
@@ -316,7 +316,7 @@ def get_current_picture(camera_config, width, height):
     return sio.getvalue()
 
 
-def set_picture_cache(camera_id, sequence, content):
+def set_picture_cache(camera_id, sequence, width, content):
     global _current_pictures_cache
     
     if not content:
@@ -327,16 +327,16 @@ def set_picture_cache(camera_id, sequence, content):
     if len(cache) >= settings.PICTURE_CACHE_SIZE:
         cache.pop(0) # drop the first item
     
-    cache.append((sequence, content))
+    cache.append((sequence, width, content))
 
 
-def get_picture_cache(camera_id, sequence):
+def get_picture_cache(camera_id, sequence, width):
     global _current_pictures_cache
     
     cache = _current_pictures_cache.setdefault(camera_id, [])
 
-    for (seq, content) in cache:
-        if seq >= sequence:
+    for (seq, w, content) in cache:
+        if (seq >= sequence) and (width >= w):
             return content
         
     return None
index c62bbe040f65443417fd3366bb0832d987acb681..e284f39f5ef7f44e33949bc134b27397fe3e1b4b 100644 (file)
@@ -23,9 +23,6 @@ from tornado.httpclient import AsyncHTTPClient, HTTPClient, HTTPRequest
 import settings
 
 
-_snapshot_cache = {}
-
-
 def _make_request(host, port, username, password, uri, method='GET', data=None, query=None):
     url = '%(scheme)s://%(host)s:%(port)s%(uri)s' % {
             'scheme': 'http',
@@ -175,8 +172,6 @@ def set_preview(host, port, username, password, camera_id, controls, callback):
 
 
 def get_current_picture(host, port, username, password, camera_id, callback, width, height):
-    global _snapshot_cache
-    
     logging.debug('getting current picture for remote camera %(id)s on %(host)s:%(port)s' % {
             'id': camera_id,
             'host': host,
@@ -192,15 +187,7 @@ def get_current_picture(host, port, username, password, camera_id, callback, wid
     
     request = _make_request(host, port, username, password, '/picture/%(id)s/current/' % {'id': camera_id}, query=query)
     
-    cache_key = (host, port, camera_id)
-    cached = _snapshot_cache.setdefault(cache_key, {'pending': 0, 'jpg': None})
-    if cached['pending'] > 0: # a pending request for this snapshot exists
-        return callback(cached['jpg'])
-    
     def on_response(response):
-        cached['pending'] -= 1
-        cached['picture'] = response.body
-        
         if response.error:
             logging.error('failed to get current picture for remote camera %(id)s on %(host)s:%(port)s: %(msg)s' % {
                     'id': camera_id,
@@ -212,8 +199,6 @@ def get_current_picture(host, port, username, password, camera_id, callback, wid
         
         callback(response.body)
     
-    cached['pending'] += 1
-    
     http_client = AsyncHTTPClient()
     http_client.fetch(request, on_response)
 
index c85f6e331de3272376f51eca0e39f7c7ace195ca..12b9b17ad771b6efb8f8e78cd8ca2aa6d77f5157 100644 (file)
@@ -377,7 +377,7 @@ function makeComboValidator($select, required) {
     
     $select.addClass('validator');
     $select.addClass('combo-validator');
-    $input.each(function () {
+    $select.each(function () {
         this.validate = validate;
     });
 }