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)
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)
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):
_MOVIE_EXTS = ['.avi', '.mp4']
# a dictionary indexed by camera_id containing
-# tuples of (sequence, content)
+# tuples of (sequence, width, content)
_current_pictures_cache = {}
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:
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
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',
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,
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,
callback(response.body)
- cached['pending'] += 1
-
http_client = AsyncHTTPClient()
http_client.fetch(request, on_response)
$select.addClass('validator');
$select.addClass('combo-validator');
- $input.each(function () {
+ $select.each(function () {
this.validate = validate;
});
}