From: Calin Crisan Date: Thu, 24 Nov 2016 13:21:49 +0000 (+0200) Subject: capture fps measuring improvements X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=6bf8dfe1094488296b9256d9cab71241e04929b1;p=motioneye-debian capture fps measuring improvements --- diff --git a/motioneye/mjpgclient.py b/motioneye/mjpgclient.py index 1c3199e..ecd4a05 100644 --- a/motioneye/mjpgclient.py +++ b/motioneye/mjpgclient.py @@ -48,7 +48,6 @@ class MjpgClient(IOStream): self._last_access = None self._last_jpg = None self._last_jpg_times = [] - self._fps = 0 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) IOStream.__init__(self, s) @@ -71,13 +70,26 @@ class MjpgClient(IOStream): if now - MjpgClient._last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: 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}) - + if settings.MOTION_RESTART_ON_ERRORS: motionctl.stop(invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) MjpgClient._last_erroneous_close_time = now + + def get_last_jpg(self): + self._last_access = time.time() + return self._last_jpg + + def get_fps(self): + if len(self._last_jpg_times) < self._FPS_LEN: + return 0 # not enough "samples" + + if time.time() - self._last_jpg_times[-1] > 1: + return 0 # everything below 1 fps is considered 0 + return (len(self._last_jpg_times) - 1) / (self._last_jpg_times[-1] - self._last_jpg_times[0]) + def _check_error(self): if self.socket is None: logging.warning('mjpg client connection for camera %(camera_id)s on port %(port)s is closed' % { @@ -208,9 +220,6 @@ class MjpgClient(IOStream): self._last_jpg_times.append(time.time()) while len(self._last_jpg_times) > self._FPS_LEN: self._last_jpg_times.pop(0) - - if len(self._last_jpg_times) == self._FPS_LEN: - self._fps = (len(self._last_jpg_times) - 1) / (self._last_jpg_times[-1] - self._last_jpg_times[0]) self._seek_content_length() @@ -248,9 +257,8 @@ def get_jpg(camera_id): MjpgClient.clients[camera_id] = client client = MjpgClient.clients[camera_id] - client._last_access = time.time() - return client._last_jpg + return client.get_last_jpg() def get_fps(camera_id): @@ -258,7 +266,7 @@ def get_fps(camera_id): if client is None: return 0 - return client._fps + return client.get_fps() def close_all(invalidate=False):