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)
# 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
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)
_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 = []
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)
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)
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
}
}
- 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;
}
if (snapshotUrl) {
snapshotUrl = addAuthParams('GET', snapshotUrl);
}
- if (mjpgUrl && dict['proto'] != 'mjpeg') {
- mjpgUrl = addAuthParams('GET', mjpgUrl);
- }
}
$('#streamingSnapshotUrlEntry').val(snapshotUrl); markHideIfNull(!snapshotUrl, 'streamingSnapshotUrlEntry');
}
}
- 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;
}