From 7f8873afd7adb0f5fe8a063ece1f7fe8df15b466 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 5 Jul 2015 17:48:52 +0300 Subject: [PATCH] removed local picture caching mechanism, as it was useless, especially at high framerates --- motioneye.py | 2 -- settings_default.py | 6 ------ src/handlers.py | 15 --------------- src/mediafiles.py | 33 +-------------------------------- src/mjpgclient.py | 3 --- static/js/frame.js | 5 ++--- static/js/main.js | 8 ++------ 7 files changed, 5 insertions(+), 67 deletions(-) diff --git a/motioneye.py b/motioneye.py index 0a72083..1beb6ec 100755 --- a/motioneye.py +++ b/motioneye.py @@ -66,8 +66,6 @@ def _configure_settings(): set_default_setting('REMOTE_REQUEST_TIMEOUT', 10) set_default_setting('MJPG_CLIENT_TIMEOUT', 10) set_default_setting('MJPG_CLIENT_IDLE_TIMEOUT', 10) - set_default_setting('PICTURE_CACHE_SIZE', 8) - set_default_setting('PICTURE_CACHE_LIFETIME', 60) set_default_setting('SMB_SHARES', False) set_default_setting('SMB_MOUNT_ROOT', '/media') set_default_setting('WPA_SUPPLICANT_CONF', None) diff --git a/settings_default.py b/settings_default.py index 3dc11d6..d200cc3 100644 --- a/settings_default.py +++ b/settings_default.py @@ -56,12 +56,6 @@ MJPG_CLIENT_TIMEOUT = 10 # timeout in seconds after which an idle mjpg client is removed (set to 0 to disable) MJPG_CLIENT_IDLE_TIMEOUT = 10 -# the maximal number of entries per camera in the current pictures cache -PICTURE_CACHE_SIZE = 8 - -# the number of seconds that a cached picture is valid -PICTURE_CACHE_LIFETIME = 60 - # enable SMB shares (requires root) SMB_SHARES = False diff --git a/src/handlers.py b/src/handlers.py index e33c635..56b99e3 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -741,35 +741,20 @@ class PictureHandler(BaseHandler): def current(self, camera_id): self.set_header('Content-Type', 'image/jpeg') - sequence = self.get_argument('seq', None) - if sequence: - sequence = int(sequence) - 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.try_finish(picture) - camera_config = config.get_camera(camera_id) if utils.local_motion_camera(camera_config): picture = mediafiles.get_current_picture(camera_config, width=width, height=height) - if sequence and picture: - mediafiles.set_picture_cache(camera_id, sequence, width, picture) - self.set_cookie('motion_detected_' + str(camera_id), str(motionctl.is_motion_detected(camera_id)).lower()) self.try_finish(picture) elif utils.remote_camera(camera_config): def on_response(motion_detected=False, picture=None, error=None): - if sequence and picture: - mediafiles.set_picture_cache(camera_id, sequence, width, picture) - self.set_cookie('motion_detected_' + str(camera_id), str(motion_detected).lower()) self.try_finish(picture) diff --git a/src/mediafiles.py b/src/mediafiles.py index f7c5fc1..c4f615e 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -42,10 +42,6 @@ import utils _PICTURE_EXTS = ['.jpg'] _MOVIE_EXTS = ['.avi', '.mp4'] -# a dictionary indexed by camera_id containing -# tuples of (moment, sequence, width, content) -_current_pictures_cache = {} - # a cache list of paths to movies without preview _previewless_movie_files = [] @@ -757,7 +753,7 @@ def get_current_picture(camera_config, width, height): return None if width is height is None: - return jpg + return jpg # no server-side resize needed sio = StringIO.StringIO(jpg) image = Image.open(sio) @@ -783,33 +779,6 @@ def get_current_picture(camera_config, width, height): return sio.getvalue() -def set_picture_cache(camera_id, sequence, width, content): - if not content: - return - - cache = _current_pictures_cache.setdefault(camera_id, []) - - if len(cache) >= settings.PICTURE_CACHE_SIZE: - cache.pop(0) # drop the first item - - cache.append((datetime.datetime.utcnow(), sequence, width, content)) - - -def get_picture_cache(camera_id, sequence, width): - cache = _current_pictures_cache.setdefault(camera_id, []) - now = datetime.datetime.utcnow() - - for (moment, seq, w, content) in cache: - delta = now - moment - if delta.days * 86400 + delta.seconds > settings.PICTURE_CACHE_LIFETIME: - continue - - if (seq >= sequence) and ((width is w is None) or (width >= w)): - return content - - return None - - def get_prepared_cache(key): return _prepared_files.pop(key, None) diff --git a/src/mjpgclient.py b/src/mjpgclient.py index d576d81..8c8de0e 100644 --- a/src/mjpgclient.py +++ b/src/mjpgclient.py @@ -257,9 +257,6 @@ def _garbage_collector(): def get_jpg(camera_id): - if not motionctl.running(): - return None - if camera_id not in MjpgClient.clients: # mjpg client not started yet for this camera diff --git a/static/js/frame.js b/static/js/frame.js index 028279d..0a91165 100644 --- a/static/js/frame.js +++ b/static/js/frame.js @@ -123,9 +123,8 @@ function refreshCameraFrame() { } } - var timestamp = Math.round(new Date().getTime()); - - var uri = baseUri + 'picture/' + cameraId + '/current/?seq=' + timestamp; + var timestamp = new Date().getTime(); + var uri = baseUri + 'picture/' + cameraId + '/current/?_=' + timestamp; if (cameraFrame.serverSideResize) { uri += '&width=' + img.width; } diff --git a/static/js/main.js b/static/js/main.js index 6b7a109..e4dbe78 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1589,9 +1589,6 @@ function dict2CameraUi(dict) { if (snapshotUrl) { snapshotUrl = addAuthParams('GET', snapshotUrl); } - if (mjpgUrl && dict['proto'] != 'mjpeg') { - mjpgUrl = addAuthParams('GET', mjpgUrl); - } } $('#streamingSnapshotUrlEntry').val(snapshotUrl); markHideIfNull(!snapshotUrl, 'streamingSnapshotUrlEntry'); @@ -3778,9 +3775,8 @@ function refreshCameraFrames() { } } - var timestamp = Math.round(new Date().getTime()); - - var uri = baseUri + 'picture/' + cameraId + '/current/?seq=' + timestamp; + var timestamp = new Date().getTime(); + var uri = baseUri + 'picture/' + cameraId + '/current/?_=' + timestamp; if (serverSideResize) { uri += '&width=' + img.width; } -- 2.39.5