From f85361ae67e7b77314b3d2f29701e63fad9dfe7e Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 10 Jul 2026 09:48:13 +0100 Subject: [PATCH] Subclass the mjpegstream descriptor --- .../things/camera/__init__.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index 8891b2bf..648264fd 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -250,6 +250,24 @@ class MJPEGStreamWithTimestamp(lt.outputs.MJPEGStream): self.notify_new_frame, entry.index ) +class MJPEGStreamDescriptorWithTimestamp(lt.outputs.MJPEGStreamDescriptor): + """Subclass the Labthings descriptor to return our own class.""" + + def __get__( + self, obj: Optional[lt.Thing], type: type[lt.Thing] | None = None # noqa: A002 + ) -> MJPEGStreamWithTimestamp | Self: + """Return our own MJPEG Stream with timestamp.""" + if obj is None: + return self + try: + return obj.__dict__[self.name] + except KeyError: + obj.__dict__[self.name] = MJPEGStreamWithTimestamp( + **self._kwargs, + thing_server_interface=obj._thing_server_interface, + ) + return obj.__dict__[self.name] + class BaseCamera(OFMThing, ABC): """The base class for all cameras. All cameras must directly inherit from this class. @@ -262,8 +280,8 @@ class BaseCamera(OFMThing, ABC): _all_background_detectors: Mapping[str, BackgroundDetectAlgorithm] = lt.thing_slot() - mjpeg_stream = lt.outputs.MJPEGStreamDescriptor() - lores_mjpeg_stream = lt.outputs.MJPEGStreamDescriptor() + mjpeg_stream = MJPEGStreamDescriptorWithTimestamp() + lores_mjpeg_stream = MJPEGStreamDescriptorWithTimestamp() _memory_buffer = CameraMemoryBuffer() supports_focus_fom: bool = False