forked from platypush/platypush
Improved camera.pi logic
This commit is contained in:
parent
57baa0c64a
commit
6ba71b52e7
1 changed files with 20 additions and 11 deletions
|
@ -116,7 +116,7 @@ class CameraPiBackend(Backend):
|
||||||
if video_file:
|
if video_file:
|
||||||
self.camera.start_recording(video_file, format=format)
|
self.camera.start_recording(video_file, format=format)
|
||||||
while True:
|
while True:
|
||||||
self.camera.wait_recording(60)
|
self.camera.wait_recording(2)
|
||||||
else:
|
else:
|
||||||
connection = self.server_socket.accept()[0].makefile('wb')
|
connection = self.server_socket.accept()[0].makefile('wb')
|
||||||
self.logger.info('Accepted client connection on port {}'.
|
self.logger.info('Accepted client connection on port {}'.
|
||||||
|
@ -125,7 +125,7 @@ class CameraPiBackend(Backend):
|
||||||
try:
|
try:
|
||||||
self.camera.start_recording(connection, format=format)
|
self.camera.start_recording(connection, format=format)
|
||||||
while True:
|
while True:
|
||||||
self.camera.wait_recording(60)
|
self.camera.wait_recording(2)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
self.logger.info('Client closed connection')
|
self.logger.info('Client closed connection')
|
||||||
try:
|
try:
|
||||||
|
@ -138,8 +138,14 @@ class CameraPiBackend(Backend):
|
||||||
|
|
||||||
self._recording_thread = None
|
self._recording_thread = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.camera.stop_recording()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if self._recording_thread:
|
if self._recording_thread:
|
||||||
self._recording_thread.join()
|
self.logger.info('Recording already running')
|
||||||
|
return
|
||||||
|
|
||||||
self.logger.info('Starting camera recording')
|
self.logger.info('Starting camera recording')
|
||||||
self._recording_thread = Thread(target=recording_thread)
|
self._recording_thread = Thread(target=recording_thread)
|
||||||
|
@ -154,13 +160,14 @@ class CameraPiBackend(Backend):
|
||||||
try:
|
try:
|
||||||
self.camera.stop_recording()
|
self.camera.stop_recording()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.info('Failed to stop recording')
|
self.logger.warning('Failed to stop recording')
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
super().run()
|
super().run()
|
||||||
|
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
|
try:
|
||||||
msg = self.redis.get_message(self.redis_queue)
|
msg = self.redis.get_message(self.redis_queue)
|
||||||
|
|
||||||
if msg.get('action') == self.CameraAction.START_RECORDING:
|
if msg.get('action') == self.CameraAction.START_RECORDING:
|
||||||
|
@ -169,6 +176,8 @@ class CameraPiBackend(Backend):
|
||||||
self.stop_recording()
|
self.stop_recording()
|
||||||
elif msg.get('action') == self.CameraAction.TAKE_PICTURE:
|
elif msg.get('action') == self.CameraAction.TAKE_PICTURE:
|
||||||
self.take_picture(image_file=msg.get('image_file'))
|
self.take_picture(image_file=msg.get('image_file'))
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception(e)
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue