Catch already-recording error when starting GPU preview

This commit is contained in:
Joel Collins 2019-02-25 18:15:16 +00:00
parent 6b3dca9f61
commit f54250a638

View file

@ -228,6 +228,7 @@ 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."""
self.start_stream_recording()
self.camera.start_preview(fullscreen=fullscreen, window=window) self.camera.start_preview(fullscreen=fullscreen, window=window)
self.state['preview_active'] = True self.state['preview_active'] = True
return True return True
@ -319,9 +320,10 @@ class StreamingCamera(BaseCamera):
# Stop the camera video recording on port 1 # Stop the camera video recording on port 1
try: try:
self.camera.stop_recording(splitter_port=splitter_port) self.camera.stop_recording(splitter_port=splitter_port)
logging.info("Stopped MJPEG stream on port {1}. Switching to {0}.".format(resolution, splitter_port))
except picamera.exc.PiCameraNotRecording: except picamera.exc.PiCameraNotRecording:
logging.info("Not recording on splitter_port {}".format(splitter_port)) logging.info("Not recording on splitter_port {}".format(splitter_port))
else:
logging.info("Stopped MJPEG stream on port {1}. Switching to {0}.".format(resolution, splitter_port))
# Increase the resolution for taking an image # Increase the resolution for taking an image
self.camera.resolution = resolution self.camera.resolution = resolution
@ -346,18 +348,26 @@ class StreamingCamera(BaseCamera):
resolution = self.config['video_resolution'] # Default to video recording resolution resolution = self.config['video_resolution'] # Default to video recording resolution
# Reduce the resolution for video streaming # Reduce the resolution for video streaming
self.camera.resolution = resolution try:
self.camera._check_recording_stopped()
except picamera.exc.PiCameraRuntimeError:
logging.info("Error while changing resolution: Recording already running.")
else:
self.camera.resolution = resolution
# If the stream should be active # If the stream should be active
if self.state['stream_active']: if self.state['stream_active']:
# Start recording on stream port try:
self.camera.start_recording( # Start recording on stream port
self.stream, self.camera.start_recording(
format='mjpeg', self.stream,
quality=self.config['jpeg_quality'], format='mjpeg',
splitter_port=splitter_port) quality=self.config['jpeg_quality'],
splitter_port=splitter_port)
logging.debug("Started MJPEG stream at {} on port {}".format(resolution, splitter_port)) except picamera.exc.PiCameraAlreadyRecording:
logging.info("Error while starting preview: Recording already running.")
else:
logging.debug("Started MJPEG stream at {} on port {}".format(resolution, splitter_port))
def capture( def capture(
self, self,