From: Calin Crisan Date: Wed, 31 Aug 2016 17:23:23 +0000 (+0300) Subject: added support for motion version 3.4.x X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=0767f4daf75407bef97436b4518da8bc1406a03c;p=motioneye-debian added support for motion version 3.4.x --- diff --git a/motioneye/config.py b/motioneye/config.py index 21f872f..297865e 100644 --- a/motioneye/config.py +++ b/motioneye/config.py @@ -30,10 +30,10 @@ import urlparse from tornado.ioloop import IOLoop import diskctl +import motionctl import powerctl import settings import tasks -import update import uploadservices import utils import v4l2ctl @@ -52,9 +52,6 @@ _additional_config_funcs = [] _additional_structure_cache = {} _monitor_command_cache = {} -# starting with r490 motion config directives have changed a bit -_LAST_OLD_CONFIG_VERSIONS = (490, '3.2.12') - # when using the following video codecs, the ffmpeg_variable_bitrate parameter appears to have an exponential effect _EXPONENTIAL_QUALITY_CODECS = ['mpeg4', 'msmpeg4', 'swf', 'flv', 'mov', 'ogg', 'mkv'] _EXPONENTIAL_QUALITY_FACTOR = 100000 # voodoo @@ -131,7 +128,7 @@ def get_main(as_lines=False): no_convert=['@admin_username', '@admin_password', '@normal_username', '@normal_password']) _get_additional_config(main_config) - _set_default_motion(main_config, old_motion=is_old_motion()) + _set_default_motion(main_config, old_config_format=motionctl.has_old_config_format()) _main_config_cache = main_config @@ -301,10 +298,10 @@ def get_camera(camera_id, as_lines=False): camera_config['@enabled'] = _CAMERA_CONFIG_FILE_NAME % {'id': camera_id} in threads camera_config['@id'] = camera_id - old_motion = is_old_motion() + old_config_format = motionctl.has_old_config_format() # adapt directives from old configuration, if needed - if old_motion: + if old_config_format: logging.debug('using old motion config directives') if 'output_normal' in camera_config: @@ -363,10 +360,10 @@ def set_camera(camera_id, camera_config): camera_config = dict(camera_config) if utils.local_motion_camera(camera_config): - old_motion = is_old_motion() + old_config_format = motionctl.has_old_config_format() # adapt directives to old configuration, if needed - if old_motion: + if old_config_format: logging.debug('using old motion config directives') if 'output_pictures' in camera_config: @@ -1489,72 +1486,6 @@ def restore(content): return None -def is_old_motion(): - import motionctl - - try: - binary, version = motionctl.find_motion() # @UnusedVariable - - if version.startswith('trunkREV'): # e.g. "trunkREV599" - version = int(version[8:]) - return version <= _LAST_OLD_CONFIG_VERSIONS[0] - - elif version.lower().count('git'): # e.g. "Unofficial-Git-a5b5f13" or "3.2.12+git20150927mrdave" - return False # all git versions are assumed to be new - - else: # stable release, should be in the format "x.y.z" - return update.compare_versions(version, _LAST_OLD_CONFIG_VERSIONS[1]) <= 0 - - except: - return False - - -def motion_rtsp_support(): - import motionctl - - try: - binary, version = motionctl.find_motion() # @UnusedVariable - - if version.startswith('trunkREV'): # e.g. trunkREV599 - version = int(version[8:]) - if version > _LAST_OLD_CONFIG_VERSIONS[0]: - return ['tcp'] - - elif version.lower().count('git'): # e.g. Unofficial-Git-a5b5f13 - return ['tcp', 'udp'] # all git versions are assumed to support both transport protocols - - else: # stable release, should be in the format x.y.z - return [] - - except: - return [] - - -def motion_mmal_support(): - import motionctl - - try: - binary, version = motionctl.find_motion() # @UnusedVariable - - return version == 'mmaltest' - - except: - return False - - -def motion_new_movie_format_support(): - import motionctl - - try: - binary, version = motionctl.find_motion() # @UnusedVariable - - # any git version is supposed to accept newer formats - return version.lower().count('git') - - except: - return False - - def invalidate(): global _main_config_cache global _camera_config_cache @@ -1741,7 +1672,7 @@ def _dict_to_conf(lines, data, list_names=[]): return lines -def _set_default_motion(data, old_motion): +def _set_default_motion(data, old_config_format): data.setdefault('@enabled', True) data.setdefault('@show_advanced', False) @@ -1752,7 +1683,7 @@ def _set_default_motion(data, old_motion): data.setdefault('setup_mode', False) - if old_motion: + if old_config_format: data.setdefault('control_port', settings.MOTION_CONTROL_PORT) data.setdefault('control_html_output', True) data.setdefault('control_localhost', settings.MOTION_CONTROL_LOCALHOST) @@ -1839,7 +1770,7 @@ def _set_default_motion_camera(camera_id, data): data.setdefault('movie_filename', '%Y-%m-%d/%H-%M-%S') data.setdefault('max_movie_time', 0) data.setdefault('ffmpeg_output_movies', False) - if motion_new_movie_format_support(): + if motionctl.has_new_movie_format_support(): data.setdefault('ffmpeg_video_codec', 'mp4') # will use h264 codec data.setdefault('ffmpeg_variable_bitrate', _MAX_FFMPEG_VARIABLE_BITRATE / 4) # 75% diff --git a/motioneye/handlers.py b/motioneye/handlers.py index 610317d..09ea275 100644 --- a/motioneye/handlers.py +++ b/motioneye/handlers.py @@ -205,8 +205,8 @@ class MainHandler(BaseHandler): hostname=socket.gethostname(), title=self.get_argument('title', None), admin_username=config.get_main().get('@admin_username'), - old_motion=config.is_old_motion(), - motion_new_movie_format_support=config.motion_new_movie_format_support(), + has_streaming_auth=motionctl.has_streaming_auth(), + has_new_movie_format_support=motionctl.has_new_movie_format_support(), has_motion=bool(motionctl.find_motion())) @@ -565,7 +565,7 @@ class ConfigHandler(BaseHandler): if scheme in ['http', 'https']: utils.test_mjpeg_url(self.get_all_arguments(), auth_modes=['basic'], allow_jpeg=True, callback=on_response) - elif config.motion_rtsp_support() and scheme == 'rtsp': + elif motionctl.get_rtsp_support() and scheme == 'rtsp': utils.test_rtsp_url(self.get_all_arguments(), callback=on_response) else: diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index 2950770..de103d4 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -25,13 +25,16 @@ import time from tornado.ioloop import IOLoop -import config import powerctl import settings +import update import utils _MOTION_CONTROL_TIMEOUT = 5 +# starting with r490 motion config directives have changed a bit +_LAST_OLD_CONFIG_VERSIONS = (490, '3.2.12') + _started = False _motion_binary_cache = None _motion_detected = {} @@ -65,12 +68,15 @@ def find_motion(): result = re.findall('motion Version ([^,]+)', help, re.IGNORECASE) version = result and result[0] or '' + logging.debug('using motion version %s' % version) + _motion_binary_cache = (binary, version) return _motion_binary_cache def start(deferred=False): + import config import mjpgclient if deferred: @@ -289,6 +295,8 @@ def set_motion_detected(camera_id, motion_detected): def camera_id_to_thread_id(camera_id): + import config + # find the corresponding thread_id # (which can be different from camera_id) camera_ids = config.get_camera_ids() @@ -306,6 +314,8 @@ def camera_id_to_thread_id(camera_id): def thread_id_to_camera_id(thread_id): + import config + main_config = config.get_main() threads = main_config.get('thread', '') @@ -316,7 +326,60 @@ def thread_id_to_camera_id(thread_id): return None +def has_old_config_format(): + try: + binary, version = find_motion() # @UnusedVariable + + if version.startswith('trunkREV'): # e.g. "trunkREV599" + version = int(version[8:]) + return version <= _LAST_OLD_CONFIG_VERSIONS[0] + + elif version.lower().count('git'): # e.g. "Unofficial-Git-a5b5f13" or "3.2.12+git20150927mrdave" + return False # all git versions are assumed to be new + + else: # stable release, should have the format "x.y.z" + return update.compare_versions(version, _LAST_OLD_CONFIG_VERSIONS[1]) <= 0 + + except: + return False + + +def has_streaming_auth(): + return not has_old_config_format() + + +def has_new_movie_format_support(): + try: + binary, version = find_motion() # @UnusedVariable + + return version.lower().count('git') or update.compare_versions(version, '3.4') >= 0 + + except: + return False + + +def get_rtsp_support(): + try: + binary, version = find_motion() # @UnusedVariable + + if version.startswith('trunkREV'): # e.g. trunkREV599 + version = int(version[8:]) + if version > _LAST_OLD_CONFIG_VERSIONS[0]: + return ['tcp'] + + elif version.lower().count('git') or update.compare_versions(version, '3.4') >= 0: + return ['tcp', 'udp'] # all git versions are assumed to support both transport protocols + + else: # stable release, should be in the format x.y.z + return [] + + except: + return [] + + def _disable_initial_motion_detection(): + import config + for camera_id in config.get_camera_ids(): camera_config = config.get_camera(camera_id) if not utils.local_motion_camera(camera_config): diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index 2e82f01..142796f 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -581,7 +581,7 @@ ? - {% if not old_motion %} + {% if has_streaming_auth %} Authentication Mode @@ -702,7 +702,7 @@ - {% if motion_new_movie_format_support %} + {% if has_new_movie_format_support %} diff --git a/motioneye/utils.py b/motioneye/utils.py index 98a9dc5..d9258fe 100644 --- a/motioneye/utils.py +++ b/motioneye/utils.py @@ -428,7 +428,7 @@ def test_mjpeg_url(data, auth_modes, allow_jpeg, callback): def test_rtsp_url(data, callback): - import config + import motionctl scheme = data.get('scheme', 'rtsp') host = data.get('host', '127.0.0.1') @@ -584,7 +584,7 @@ def test_rtsp_url(data, callback): called[0] = True cameras = [] - rtsp_support = config.motion_rtsp_support() + rtsp_support = motionctl.get_rtsp_support() if identifier: identifier = ' ' + identifier