# timeout in seconds to wait for an access to a mjpg client before removing it
MJPG_CLIENT_TIMEOUT = 10
+
+# the maximal number of entries per camera in the current pictures cache
+PICTURE_CACHE_SIZE = 8
def current(self, camera_id):
self.set_header('Content-Type', 'image/jpeg')
+ sequence = self.get_argument('seq', None)
+ if sequence:
+ sequence = int(sequence)
+
+ picture = sequence and mediafiles.get_picture_cache(camera_id, sequence) or None
+
+ if picture is not None:
+ return self.finish(picture)
+
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))
+
+ if sequence and picture:
+ mediafiles.set_picture_cache(camera_id, sequence, picture)
self.finish(picture)
else:
def on_response(picture):
+ if sequence and picture:
+ mediafiles.set_picture_cache(camera_id, sequence, picture)
+
self.finish(picture)
remote.get_current_picture(
import config
import mjpgclient
+import settings
import utils
_PICTURE_EXTS = ['.jpg']
_MOVIE_EXTS = ['.avi', '.mp4']
+# a dictionary indexed by camera_id containing
+# tuples of (sequence, content)
+_current_pictures_cache = {}
+
def _list_media_files(dir, exts, prefix=None):
full_paths = []
image.save(sio, format='JPEG')
return sio.getvalue()
+
+
+def set_picture_cache(camera_id, sequence, content):
+ global _current_pictures_cache
+
+ 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((sequence, content))
+
+
+def get_picture_cache(camera_id, sequence):
+ global _current_pictures_cache
+
+ cache = _current_pictures_cache.setdefault(camera_id, [])
+
+ for (seq, content) in cache:
+ if seq >= sequence:
+ return content
+
+ return None
import settings
+
_snapshot_cache = {}
timestamp /= 500;
}
timestamp = Math.round(timestamp);
- img.src = '/picture/' + cameraId + '/current/?_=' + timestamp + '&width=' + img.width;
+ img.src = '/picture/' + cameraId + '/current/?seq=' + timestamp + '&width=' + img.width;
img.loading = true;
}