From: Calin Crisan Date: Sat, 26 Oct 2013 13:45:02 +0000 (+0300) Subject: added caching mechanism for v4l ctl X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=32f03abaef7385c003f1589b02fb59e7a701365f;p=motioneye-debian added caching mechanism for v4l ctl --- diff --git a/doc/todo.txt b/doc/todo.txt index 399df2d..07de28b 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,15 +1,18 @@ -> add an autoupdate mechanism +-> cache jpegs from remote cameras locally +-> cache prevention query arg should be according to the refresh rate +-> the camera is not available on page load, it is never shown afterwards - increase the timeout +-> click to zoom on cameras +-> make camera frames positions configurable +-> remote cameras are presented as http:///dev/video0 +-> add a view log functionality +-> add a previewer for movies +-> add a previewer for snapshots -> style scroll bars -> hint text next to section titles -> clickable hints --> make camera frames positions configurable --> add a view log functionality --> click to zoom on cameras --> add a previewer for movies --> add a previewer for snapshots --> add a motioneye.svg icon -> implement working schedule (add another combo deciding what to do during working schedule) -> add other options applicable only to special devices (rpi): wifi settings, notifications diff --git a/src/handlers.py b/src/handlers.py index d3e8371..5ec4946 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -353,7 +353,7 @@ class ConfigHandler(BaseHandler): if remote_ui_config is None: cameras.append({ 'id': camera_id, - 'name': '<error>', + 'name': '<error>', # TODO add the camera url here 'enabled': False, 'streaming_framerate': 1, 'framerate': 1 diff --git a/src/v4l2ctl.py b/src/v4l2ctl.py index f41e725..7a28bbe 100644 --- a/src/v4l2ctl.py +++ b/src/v4l2ctl.py @@ -4,7 +4,14 @@ import re import subprocess +_resolutions_cache = {} +_ctrls_cache = {} +_ctrl_values_cache = {} + + def list_devices(): + global _resolutions_cache + logging.debug('listing v4l devices...') devices = [] @@ -22,11 +29,21 @@ def list_devices(): else: name = line.split('(')[0].strip() + + # clear the cache + _resolutions_cache = {} + _ctrls_cache = {} + _ctrl_values_cache = {} return devices def list_resolutions(device): + global _resolutions_cache + + if device in _resolutions_cache: + return _resolutions_cache[device] + logging.debug('listing resolutions of device %(device)s...' % {'device': device}) resolutions = set() @@ -47,7 +64,10 @@ def list_resolutions(device): logging.debug('found resolution %(width)sx%(height)s for device %(device)s' % { 'device': device, 'width': width, 'height': height}) - return list(sorted(resolutions, key=lambda r: (r[0], r[1]))) + resolutions = list(sorted(resolutions, key=lambda r: (r[0], r[1]))) + _resolutions_cache[device] = resolutions + + return resolutions def get_brightness(device): @@ -83,6 +103,11 @@ def set_hue(device, value): def _get_ctrl(device, control): + global _ctrl_values_cache + + if device in _ctrl_values_cache and control in _ctrl_values_cache[device]: + return _ctrl_values_cache[device][control] + controls = _list_ctrls(device) properties = controls.get(control) if properties is None: @@ -111,6 +136,8 @@ def _get_ctrl(device, control): def _set_ctrl(device, control, value): + global _ctrl_values_cache + controls = _list_ctrls(device) properties = controls.get(control) if properties is None: @@ -119,6 +146,8 @@ def _set_ctrl(device, control, value): return + _ctrl_values_cache.setdefault(device, {})[control] = value + # adjust the value range if 'min' in properties and 'max' in properties: min_value = int(properties['min']) @@ -138,6 +167,11 @@ def _set_ctrl(device, control, value): def _list_ctrls(device): + global _ctrls_cache + + if device in _ctrls_cache: + return _ctrls_cache[device] + output = subprocess.check_output('v4l2-ctl -d %(device)s --list-ctrls' % { 'device': device}, shell=True) @@ -154,4 +188,6 @@ def _list_ctrls(device): properties = dict([v.split('=') for v in properties.split(' ')]) controls[control] = properties + _ctrls_cache[device] = controls + return controls