]> www.vanbest.org Git - motioneye-debian/commitdiff
added support for motion version 3.4.x
authorCalin Crisan <ccrisan@gmail.com>
Wed, 31 Aug 2016 17:23:23 +0000 (20:23 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 31 Aug 2016 17:23:23 +0000 (20:23 +0300)
motioneye/config.py
motioneye/handlers.py
motioneye/motionctl.py
motioneye/templates/main.html
motioneye/utils.py

index 21f872f6c832a5fb0ee4a00d16f628cd8c458a6f..297865e0909dae77785b5b1ec8fb10ff18be28c7 100644 (file)
@@ -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%
         
index 610317d46b7f381b49faa7374b8b479bfc40349e..09ea275d461a54848013bc95e7c41a8505098df1 100644 (file)
@@ -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:
index 2950770df87eee87977cac6d25ff4e633e66d714..de103d45b0cd209b5057543379f5344165b6df1c 100644 (file)
@@ -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):
index 2e82f01716a2e6da97eec7bce9473e3792569ad1..142796f867d4d4c88f1277f22f70bf44037c11c2 100644 (file)
                         <td class="settings-item-value"><input type="text" class="styled streaming camera-config" id="streamingPortEntry"></td>
                         <td><span class="help-mark" title="sets the TCP port on which the webcam streaming server listens">?</span></td>
                     </tr>
-                    {% if not old_motion %}
+                    {% if has_streaming_auth %}
                     <tr class="settings-item advanced-setting" depends="videoStreamingEnabled">
                         <td class="settings-item-label"><span class="settings-item-label">Authentication Mode</span></td>
                         <td class="settings-item-value">
                                 <option value="swf">Small Web Format (.swf)</option>
                                 <option value="flv">Flash Video (.flv)</option>
                                 <option value="mov">QuickTime (.mov)</option>
-                                {% if motion_new_movie_format_support %}
+                                {% if has_new_movie_format_support %}
                                 <option value="ogg">Ogg (.ogg)</option>
                                 <option value="mp4">H.264 (.mp4)</option>
                                 <option value="hevc">HEVC (.mp4)</option>
index 98a9dc59a68b90e97dedf3c581e9f2d1851481a0..d9258fe200f325ae50e6052a615be59e7d16727e 100644 (file)
@@ -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