from tornado.ioloop import IOLoop
import diskctl
+import motionctl
import powerctl
import settings
import tasks
-import update
import uploadservices
import utils
import v4l2ctl
_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
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
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:
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:
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
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)
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)
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%
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()))
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:
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 = {}
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:
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()
def thread_id_to_camera_id(thread_id):
+ import config
+
main_config = config.get_main()
threads = main_config.get('thread', '')
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):
<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>
def test_rtsp_url(data, callback):
- import config
+ import motionctl
scheme = data.get('scheme', 'rtsp')
host = data.get('host', '127.0.0.1')
called[0] = True
cameras = []
- rtsp_support = config.motion_rtsp_support()
+ rtsp_support = motionctl.get_rtsp_support()
if identifier:
identifier = ' ' + identifier