From: Calin Crisan Date: Sun, 1 Dec 2013 14:05:10 +0000 (+0200) Subject: current picture cache fix; removed the secondary remote picture cache X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=1ec8df257f72a08929418d3a0055d4ca9c52795c;p=motioneye-debian current picture cache fix; removed the secondary remote picture cache --- diff --git a/src/handlers.py b/src/handlers.py index ef4daed..dbb025e 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -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): diff --git a/src/mediafiles.py b/src/mediafiles.py index ab3ceb8..e7d45ed 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -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 diff --git a/src/remote.py b/src/remote.py index c62bbe0..e284f39 100644 --- a/src/remote.py +++ b/src/remote.py @@ -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) diff --git a/static/js/ui.js b/static/js/ui.js index c85f6e3..12b9b17 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -377,7 +377,7 @@ function makeComboValidator($select, required) { $select.addClass('validator'); $select.addClass('combo-validator'); - $input.each(function () { + $select.each(function () { this.validate = validate; }); }