Draft of new semantics
This commit is contained in:
parent
b39a0653f2
commit
19af98736d
13 changed files with 252 additions and 187 deletions
|
|
@ -121,7 +121,8 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
self.stream_timeout = 20
|
||||
self.stream_timeout_enabled = False
|
||||
|
||||
self.status = {"board": None}
|
||||
self.stream_active = False
|
||||
self.record_active = False
|
||||
|
||||
self.paths = {"default": BASE_CAPTURE_PATH, "temp": TEMP_CAPTURE_PATH}
|
||||
|
||||
|
|
@ -129,8 +130,24 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
self.images = []
|
||||
self.videos = []
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def apply_settings(self, config: dict):
|
||||
def configuration(self):
|
||||
"""The current camera configuration."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def state(self):
|
||||
"""The current read-only camera state."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def settings(self):
|
||||
return self.read_settings()
|
||||
|
||||
@abstractmethod
|
||||
def update_settings(self, config: dict):
|
||||
"""Update settings from a config dictionary"""
|
||||
with self.lock:
|
||||
# Apply valid config params to camera object
|
||||
|
|
@ -187,7 +204,7 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
self.last_access = time.time()
|
||||
self.stop = False
|
||||
|
||||
if not self.status["stream_active"]:
|
||||
if not self.stream_active:
|
||||
# start background frame thread
|
||||
self.thread = threading.Thread(target=self._thread)
|
||||
self.thread.daemon = True
|
||||
|
|
@ -207,12 +224,12 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
logging.debug("Stopping worker thread")
|
||||
timeout_time = time.time() + timeout
|
||||
|
||||
if self.status["stream_active"]:
|
||||
if self.stream_active:
|
||||
self.stop = True
|
||||
self.thread.join() # Wait for stream thread to exit
|
||||
logging.debug("Waiting for stream thread to exit.")
|
||||
|
||||
while self.status["stream_active"]:
|
||||
while self.stream_active:
|
||||
if time.time() > timeout_time:
|
||||
logging.debug("Timeout waiting for worker thread close.")
|
||||
raise TimeoutError("Timeout waiting for worker thread close.")
|
||||
|
|
@ -352,7 +369,7 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
self.frames_iterator = self.frames()
|
||||
logging.debug("Entering worker thread.")
|
||||
|
||||
self.status["stream_active"] = True
|
||||
self.stream_active = True
|
||||
|
||||
for frame in self.frames_iterator:
|
||||
self.frame = frame
|
||||
|
|
@ -365,9 +382,7 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
and ( # If using timeout
|
||||
time.time() - self.last_access > self.stream_timeout
|
||||
)
|
||||
and not self.status[ # And timeout time
|
||||
"preview_active"
|
||||
] # And GPU preview is not active
|
||||
and not self.preview_active # And GPU preview is not active
|
||||
):
|
||||
self.frames_iterator.close()
|
||||
break
|
||||
|
|
@ -383,4 +398,4 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
|
||||
logging.debug("BaseCamera worker thread exiting...")
|
||||
# Set stream_activate state
|
||||
self.status["stream_active"] = False
|
||||
self.stream_active = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue