Cleaned up camera locks

This commit is contained in:
Joel Collins 2019-05-23 14:25:57 +01:00
parent 8e35ef2b29
commit 90a3a738af

View file

@ -240,9 +240,11 @@ class StreamingCamera(BaseCamera):
def start_preview(self, fullscreen=True, window=None) -> bool: def start_preview(self, fullscreen=True, window=None) -> bool:
"""Start the on board GPU camera preview.""" """Start the on board GPU camera preview."""
logging.info("Starting the GPU preview") logging.info("Starting the GPU preview")
self.start_stream_recording()
# TODO: Commented out as I honestly can't remember why this was here. May need to put back?
#self.start_stream_recording()
try: try:
with self.lock:
if not self.camera.preview: if not self.camera.preview:
logging.debug("Starting preview") logging.debug("Starting preview")
self.camera.start_preview(fullscreen=fullscreen, window=window) self.camera.start_preview(fullscreen=fullscreen, window=window)
@ -257,14 +259,11 @@ class StreamingCamera(BaseCamera):
logging.error("Suppressed a MMALError in start_preview. Exception: {}".format(e)) logging.error("Suppressed a MMALError in start_preview. Exception: {}".format(e))
except picamera.exc.PiCameraValueError as e: except picamera.exc.PiCameraValueError as e:
logging.error("Suppressed a ValueError exception in start_preview. Exception: {}".format(e)) logging.error("Suppressed a ValueError exception in start_preview. Exception: {}".format(e))
return True
def stop_preview(self) -> bool: def stop_preview(self) -> bool:
"""Stop the on board GPU camera preview.""" """Stop the on board GPU camera preview."""
with self.lock:
self.camera.stop_preview() self.camera.stop_preview()
self.state['preview_active'] = False self.state['preview_active'] = False
return True
def start_recording( def start_recording(
self, self,
@ -340,6 +339,7 @@ class StreamingCamera(BaseCamera):
splitter_port (int): Splitter port to stop recording on splitter_port (int): Splitter port to stop recording on
resolution ((int, int)): Resolution to set the camera to, after stopping recording. resolution ((int, int)): Resolution to set the camera to, after stopping recording.
""" """
with self.lock:
# If no resolution is specified, default to image_resolution # If no resolution is specified, default to image_resolution
if not resolution: if not resolution:
resolution = self.config['image_resolution'] resolution = self.config['image_resolution']
@ -367,6 +367,7 @@ class StreamingCamera(BaseCamera):
splitter_port (int): Splitter port to start recording on splitter_port (int): Splitter port to start recording on
resolution ((int, int)): Resolution to set the camera to, before starting recording. Defaults to `self.config['stream_resolution']`. resolution ((int, int)): Resolution to set the camera to, before starting recording. Defaults to `self.config['stream_resolution']`.
""" """
with self.lock:
# If stream object was destroyed # If stream object was destroyed
if not hasattr(self, 'stream'): if not hasattr(self, 'stream'):
self.stream = io.BytesIO() # Create a stream object self.stream = io.BytesIO() # Create a stream object