set_default_setting('THUMBNAILER_INTERVAL', 60)
set_default_setting('REMOTE_REQUEST_TIMEOUT', 10)
set_default_setting('MJPG_CLIENT_TIMEOUT', 10)
+ set_default_setting('MJPG_CLIENT_IDLE_TIMEOUT', 10)
set_default_setting('PICTURE_CACHE_SIZE', 8)
set_default_setting('PICTURE_CACHE_LIFETIME', 60)
set_default_setting('SMB_SHARES', False)
if ioloop._stopped:
return
- if not motionctl.running() and motionctl.started() and config.has_local_enabled_cameras():
+ if not motionctl.running() and motionctl.started() and config.get_enabled_local_motion_cameras():
try:
logging.error('motion not running, starting it')
motionctl.start()
# interval in seconds at which the thumbnail mechanism runs (set to 0 to disable)
THUMBNAILER_INTERVAL = 60
-# timeout in seconds to wait for responses when contacting a remote server
+# timeout in seconds when waiting for response from a remote motionEye server
REMOTE_REQUEST_TIMEOUT = 10
-# timeout in seconds to wait for an access to a mjpg client before removing it
+# timeout in seconds when waiting for mjpg data from the motion daemon
MJPG_CLIENT_TIMEOUT = 10
+# timeout in seconds after which an idle mjpg client is removed (set to 0 to disable)
+MJPG_CLIENT_IDLE_TIMEOUT = 10
+
# the maximal number of entries per camera in the current pictures cache
PICTURE_CACHE_SIZE = 8
return filtered_camera_ids
-def has_local_enabled_cameras():
+def get_enabled_local_motion_cameras():
if not get_main().get('@enabled'):
- return False
+ return []
camera_ids = get_camera_ids()
cameras = [get_camera(camera_id) for camera_id in camera_ids]
- return bool([c for c in cameras if c.get('@enabled') and utils.local_motion_camera(c)])
+ return [c for c in cameras if c.get('@enabled') and utils.local_motion_camera(c)]
def get_network_shares():
logging.error('connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % {
'port': self._port, 'camera_id': self._camera_id})
- motionctl.stop() # this will close all the mjpg clients
- motionctl.start()
+ motionctl.stop(invalidate=True) # this will close all the mjpg clients
+ motionctl.start(deferred=True)
MjpgClient.last_erroneous_close_time = now
logging.error('mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % {
'camera_id': camera_id, 'port': port})
- motionctl.stop() # this will close all the mjpg clients
- motionctl.start()
+ motionctl.stop(invalidate=True) # this will close all the mjpg clients
+ motionctl.start(deferred=True)
break
delta = now - last_access
delta = delta.days * 86400 + delta.seconds
- if delta > settings.MJPG_CLIENT_TIMEOUT:
- logging.debug('mjpg client for camera %(camera_id)s on port %(port)s timed out' % {
- 'camera_id': camera_id, 'port': port})
+ if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT:
+ logging.debug('mjpg client for camera %(camera_id)s on port %(port)s has been idle for %(timeout)s seconds, removing it' % {
+ 'camera_id': camera_id, 'port': port, 'timeout': settings.MJPG_CLIENT_IDLE_TIMEOUT})
client.close()
return MjpgClient.last_jpgs.get(camera_id)
-def close_all():
+def close_all(invalidate=False):
for client in MjpgClient.clients.values():
client.close()
+
+ if invalidate:
+ MjpgClient.clients = {}
+ MjpgClient.last_jpgs = {}
+ MjpgClient.last_jpg_moment = {}
+ MjpgClient.last_access = {}
+ MjpgClient.last_erroneous_close_time = 0
# schedule the garbage collector
import time
from tornado.httpclient import HTTPClient, AsyncHTTPClient, HTTPRequest
+from tornado.ioloop import IOLoop
import config
+import mjpgclient
import powerctl
import settings
import utils
set_motion_detection(camera_id, False)
-def start():
+def start(deferred=False):
+ if deferred:
+ return IOLoop.instance().add_callback(start, deferred=False)
+
global _started
_started = True
- if running() or not config.has_local_enabled_cameras():
+ enabled_local_motion_cameras = config.get_enabled_local_motion_cameras()
+ if running() or not enabled_local_motion_cameras:
return
logging.debug('starting motion')
f.write(str(pid) + '\n')
_disable_initial_motion_detection()
+
+ # if mjpg client idle timeout is disabled, create mjpg clients for all cameras by default
+ if not settings.MJPG_CLIENT_IDLE_TIMEOUT:
+ logging.debug('creating default mjpg clients for local cameras')
+ for camera in enabled_local_motion_cameras:
+ mjpgclient.get_jpg(camera['@id'])
-def stop():
- import mjpgclient
-
+def stop(invalidate=False):
global _started
_started = False
logging.debug('stopping motion')
- mjpgclient.close_all()
+ mjpgclient.close_all(invalidate=invalidate)
pid = _get_pid()
if pid is not None: