pyobs-v4l 2.0.0.dev6__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/PKG-INFO +3 -3
- pyobs_v4l-2.1.0/pyobs_v4l/v4lcamera.py +193 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/pyproject.toml +3 -3
- pyobs_v4l-2.1.0/tests/test_v4lcamera.py +127 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/uv.lock +40 -40
- pyobs_v4l-2.0.0.dev6/pyobs_v4l/v4lcamera.py +0 -131
- pyobs_v4l-2.0.0.dev6/tests/test_v4lcamera.py +0 -45
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/dependabot.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/workflows/dependabot-automerge.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/workflows/pypi.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/workflows/pyrefly.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/workflows/pytest.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.github/workflows/ruff.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.pre-commit-config.yaml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/.readthedocs.yml +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/LICENSE +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/README.md +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/Makefile +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/make.bat +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/requirements.txt +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/source/conf.py +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/docs/source/index.rst +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/pyobs_v4l/__init__.py +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/pyobs_v4l/gui.py +0 -0
- {pyobs_v4l-2.0.0.dev6 → pyobs_v4l-2.1.0}/tests/test_import.py +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyobs-v4l
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: pyobs module for V4L cameras
|
|
5
5
|
Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Requires-Dist: opencv-python<6,>=4.0
|
|
10
|
-
Requires-Dist: pyobs-core<3,>=2.
|
|
10
|
+
Requires-Dist: pyobs-core<3,>=2.13.1
|
|
11
11
|
Provides-Extra: gui
|
|
12
|
-
Requires-Dist: pyobs-core[gui]<3,>=2.
|
|
12
|
+
Requires-Dist: pyobs-core[gui]<3,>=2.13.1; extra == 'gui'
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
import threading
|
|
4
|
+
from collections.abc import AsyncGenerator, Callable
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import cv2
|
|
8
|
+
from pyobs.modules.camera import BaseVideo, Frame
|
|
9
|
+
|
|
10
|
+
log = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
# cv2's V4L2 backend calls are blocking and are made directly on the event loop thread (see
|
|
13
|
+
# _run_blocking). If the camera has gone unresponsive, they can hang indefinitely, so they're
|
|
14
|
+
# bounded with a timeout rather than let a single dead camera freeze the whole module.
|
|
15
|
+
_SDK_CALL_TIMEOUT = 5.0
|
|
16
|
+
|
|
17
|
+
# frames() warns if no frame arrived for this long. Frames legitimately take up to the camera's
|
|
18
|
+
# own frame interval, so this is much more generous than _SDK_CALL_TIMEOUT.
|
|
19
|
+
_FRAME_WAIT_TIMEOUT = 30.0
|
|
20
|
+
|
|
21
|
+
# frames queued between the reader thread and the event loop; latest wins beyond that
|
|
22
|
+
_QUEUE_SIZE = 5
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class v4lCamera(BaseVideo):
|
|
26
|
+
"""A pyobs module for V4L2 cameras, e.g. webcams.
|
|
27
|
+
|
|
28
|
+
The device is opened while the module is active and released when it goes to sleep. V4L2
|
|
29
|
+
gives no reliable exposure time or exposure start via OpenCV, so frames carry neither and
|
|
30
|
+
DATE-OBS is the frame's arrival time.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
__module__ = "pyobs_v4l"
|
|
34
|
+
|
|
35
|
+
def __init__(self, device: int = 0, color: bool = False, **kwargs: Any):
|
|
36
|
+
"""Initializes a new v4lCamera.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
device: Index of the V4L2 device, i.e. N in /dev/videoN.
|
|
40
|
+
color: Keep colour frames (RGB, colour as last axis) instead of converting them to
|
|
41
|
+
greyscale. Colour frames work for the live view, but not for grab_stack(), and
|
|
42
|
+
are stored as 3D FITS files.
|
|
43
|
+
"""
|
|
44
|
+
BaseVideo.__init__(self, **kwargs)
|
|
45
|
+
|
|
46
|
+
# store
|
|
47
|
+
self._device = device
|
|
48
|
+
self._color = color
|
|
49
|
+
|
|
50
|
+
async def open(self) -> None:
|
|
51
|
+
"""Open module."""
|
|
52
|
+
await BaseVideo.open(self)
|
|
53
|
+
|
|
54
|
+
# start streaming
|
|
55
|
+
await self.activate_camera()
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
async def _run_blocking(func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT) -> bool:
|
|
59
|
+
"""Run a blocking cv2/V4L2 call in a daemon thread, so a hung call can't freeze the module.
|
|
60
|
+
|
|
61
|
+
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
62
|
+
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
True if func completed within timeout, False if it's still running in the background.
|
|
66
|
+
"""
|
|
67
|
+
loop = asyncio.get_running_loop()
|
|
68
|
+
future: asyncio.Future[None] = loop.create_future()
|
|
69
|
+
|
|
70
|
+
def _finish() -> None:
|
|
71
|
+
# wait_for cancels the future on timeout, so guard set_result to avoid an
|
|
72
|
+
# InvalidStateError from the loop thread once the orphaned call finally ends.
|
|
73
|
+
if not future.done():
|
|
74
|
+
future.set_result(None)
|
|
75
|
+
|
|
76
|
+
def _wrapper() -> None:
|
|
77
|
+
try:
|
|
78
|
+
func()
|
|
79
|
+
finally:
|
|
80
|
+
try:
|
|
81
|
+
loop.call_soon_threadsafe(_finish)
|
|
82
|
+
except RuntimeError:
|
|
83
|
+
# event loop closed (shutdown)
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
threading.Thread(target=_wrapper, daemon=True).start()
|
|
87
|
+
try:
|
|
88
|
+
await asyncio.wait_for(future, timeout=timeout)
|
|
89
|
+
return True
|
|
90
|
+
except TimeoutError:
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
async def _open_camera(self) -> Any:
|
|
94
|
+
"""Open the V4L2 camera device, without blocking the event loop.
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
TimeoutError: If opening didn't finish in time.
|
|
98
|
+
RuntimeError: If the device could not be opened.
|
|
99
|
+
"""
|
|
100
|
+
result: list[Any] = []
|
|
101
|
+
lock = threading.Lock()
|
|
102
|
+
timed_out = False
|
|
103
|
+
|
|
104
|
+
def _open() -> None:
|
|
105
|
+
camera = cv2.VideoCapture(self._device)
|
|
106
|
+
with lock:
|
|
107
|
+
if timed_out:
|
|
108
|
+
# timed out while still opening; release the handle nobody will use
|
|
109
|
+
camera.release()
|
|
110
|
+
else:
|
|
111
|
+
result.append(camera)
|
|
112
|
+
|
|
113
|
+
if not await self._run_blocking(_open):
|
|
114
|
+
with lock:
|
|
115
|
+
timed_out = True
|
|
116
|
+
if result:
|
|
117
|
+
result.pop().release()
|
|
118
|
+
raise TimeoutError(f"Timed out opening camera device after {_SDK_CALL_TIMEOUT}s.")
|
|
119
|
+
|
|
120
|
+
# VideoCapture() doesn't raise for a missing/busy device, it just isn't opened
|
|
121
|
+
camera = result[0]
|
|
122
|
+
if not camera.isOpened():
|
|
123
|
+
camera.release()
|
|
124
|
+
raise RuntimeError(f"Could not open camera device {self._device}.")
|
|
125
|
+
return camera
|
|
126
|
+
|
|
127
|
+
def _convert(self, frame: Any) -> Any:
|
|
128
|
+
"""Convert a frame from OpenCV's BGR to greyscale, or to RGB if colour is kept."""
|
|
129
|
+
if frame.ndim != 3:
|
|
130
|
+
return frame
|
|
131
|
+
return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB if self._color else cv2.COLOR_BGR2GRAY)
|
|
132
|
+
|
|
133
|
+
async def frames(self) -> AsyncGenerator[Frame, None]:
|
|
134
|
+
"""Open the device and yield frames until BaseVideo closes the iterator.
|
|
135
|
+
|
|
136
|
+
A single reader thread owns the device for the whole activation, reads frames and hands
|
|
137
|
+
them to the event loop, and releases the device when it's told to stop. A failed read ends
|
|
138
|
+
the iterator with an error, so BaseVideo restarts it with a back-off.
|
|
139
|
+
"""
|
|
140
|
+
loop = asyncio.get_running_loop()
|
|
141
|
+
queue: asyncio.Queue[Frame | BaseException] = asyncio.Queue(maxsize=_QUEUE_SIZE)
|
|
142
|
+
stop = threading.Event()
|
|
143
|
+
camera = await self._open_camera()
|
|
144
|
+
|
|
145
|
+
def _put(item: Frame | BaseException) -> None:
|
|
146
|
+
# latest wins: a stalled event loop mustn't grow memory
|
|
147
|
+
if queue.full():
|
|
148
|
+
queue.get_nowait()
|
|
149
|
+
queue.put_nowait(item)
|
|
150
|
+
|
|
151
|
+
def _read() -> None:
|
|
152
|
+
try:
|
|
153
|
+
while not stop.is_set():
|
|
154
|
+
item: Frame | BaseException
|
|
155
|
+
try:
|
|
156
|
+
# read() returns a fresh array per call, so no copy needed
|
|
157
|
+
ok, frame = camera.read()
|
|
158
|
+
if ok and frame is not None:
|
|
159
|
+
item = Frame(data=self._convert(frame))
|
|
160
|
+
else:
|
|
161
|
+
item = RuntimeError(f"Could not read frame from camera device {self._device}.")
|
|
162
|
+
except Exception as e:
|
|
163
|
+
item = e
|
|
164
|
+
if stop.is_set():
|
|
165
|
+
return
|
|
166
|
+
try:
|
|
167
|
+
loop.call_soon_threadsafe(_put, item)
|
|
168
|
+
except RuntimeError:
|
|
169
|
+
# event loop closed (shutdown)
|
|
170
|
+
return
|
|
171
|
+
if isinstance(item, BaseException):
|
|
172
|
+
return
|
|
173
|
+
finally:
|
|
174
|
+
camera.release()
|
|
175
|
+
|
|
176
|
+
threading.Thread(target=_read, daemon=True).start()
|
|
177
|
+
try:
|
|
178
|
+
while True:
|
|
179
|
+
try:
|
|
180
|
+
item = await asyncio.wait_for(queue.get(), timeout=_FRAME_WAIT_TIMEOUT)
|
|
181
|
+
except TimeoutError:
|
|
182
|
+
log.warning("No frame from camera for %.1fs.", _FRAME_WAIT_TIMEOUT)
|
|
183
|
+
continue
|
|
184
|
+
if isinstance(item, BaseException):
|
|
185
|
+
raise item
|
|
186
|
+
yield item
|
|
187
|
+
finally:
|
|
188
|
+
# don't join the reader: if it hangs in read(), it must not block deactivation; it
|
|
189
|
+
# releases the device itself once read() returns
|
|
190
|
+
stop.set()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
__all__ = ["v4lCamera"]
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyobs-v4l"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.1.0"
|
|
4
4
|
description = "pyobs module for V4L cameras"
|
|
5
5
|
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = "MIT"
|
|
8
8
|
dependencies = [
|
|
9
9
|
"opencv-python>=4.0,<6",
|
|
10
|
-
"pyobs-core>=2.
|
|
10
|
+
"pyobs-core>=2.13.1,<3",
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
[project.optional-dependencies]
|
|
14
14
|
gui = [
|
|
15
|
-
"pyobs-core[gui]>=2.
|
|
15
|
+
"pyobs-core[gui]>=2.13.1,<3",
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
[project.scripts]
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Unit tests for the non-hardware logic in v4lCamera: constructor state, the _run_blocking
|
|
2
|
+
timeout wrapper, device opening and frames(). cv2.VideoCapture is replaced by a fake.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import threading
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import cv2
|
|
10
|
+
import numpy as np
|
|
11
|
+
import numpy.typing as npt
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from pyobs_v4l import v4lCamera
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FakeCapture:
|
|
18
|
+
"""Stands in for cv2.VideoCapture: frames come from a list, a failed read once it's empty."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, frames: list[npt.NDArray[Any]] | None = None, opened: bool = True) -> None:
|
|
21
|
+
self.frames = [] if frames is None else frames
|
|
22
|
+
self.opened = opened
|
|
23
|
+
self.released = threading.Event()
|
|
24
|
+
|
|
25
|
+
def isOpened(self) -> bool:
|
|
26
|
+
return self.opened
|
|
27
|
+
|
|
28
|
+
def read(self) -> tuple[bool, npt.NDArray[Any] | None]:
|
|
29
|
+
if self.frames:
|
|
30
|
+
return True, self.frames.pop(0)
|
|
31
|
+
return False, None
|
|
32
|
+
|
|
33
|
+
def release(self) -> None:
|
|
34
|
+
self.released.set()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _bgr(b: int, g: int, r: int) -> npt.NDArray[Any]:
|
|
38
|
+
frame = np.zeros((2, 3, 3), dtype=np.uint8)
|
|
39
|
+
frame[:, :] = (b, g, r)
|
|
40
|
+
return frame
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_constructor_defaults() -> None:
|
|
44
|
+
camera = v4lCamera()
|
|
45
|
+
assert camera._device == 0
|
|
46
|
+
assert camera._color is False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_constructor_device() -> None:
|
|
50
|
+
camera = v4lCamera(device=3)
|
|
51
|
+
assert camera._device == 3
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.asyncio
|
|
55
|
+
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
56
|
+
ran: list[bool] = []
|
|
57
|
+
|
|
58
|
+
def fast() -> None:
|
|
59
|
+
ran.append(True)
|
|
60
|
+
|
|
61
|
+
assert await v4lCamera._run_blocking(fast) is True
|
|
62
|
+
assert ran == [True]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.asyncio
|
|
66
|
+
async def test_run_blocking_times_out() -> None:
|
|
67
|
+
done = threading.Event()
|
|
68
|
+
|
|
69
|
+
def slow() -> None:
|
|
70
|
+
done.wait()
|
|
71
|
+
|
|
72
|
+
assert await v4lCamera._run_blocking(slow, timeout=0.01) is False
|
|
73
|
+
done.set()
|
|
74
|
+
await asyncio.sleep(0.05) # let the daemon thread drain before the loop closes
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.asyncio
|
|
78
|
+
async def test_open_camera_raises_if_not_opened(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
79
|
+
fake = FakeCapture(opened=False)
|
|
80
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
81
|
+
|
|
82
|
+
with pytest.raises(RuntimeError, match="Could not open"):
|
|
83
|
+
await v4lCamera()._open_camera()
|
|
84
|
+
assert fake.released.is_set()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.asyncio
|
|
88
|
+
async def test_frames_yields_greyscale_and_releases_on_close(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
89
|
+
fake = FakeCapture([_bgr(0, 0, 255), _bgr(255, 0, 0)] + [_bgr(0, 0, 0)] * 100)
|
|
90
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
91
|
+
camera = v4lCamera()
|
|
92
|
+
|
|
93
|
+
iterator = camera.frames()
|
|
94
|
+
first, second = await anext(iterator), await anext(iterator)
|
|
95
|
+
await iterator.aclose()
|
|
96
|
+
|
|
97
|
+
assert first.data.shape == (2, 3) and second.data.shape == (2, 3)
|
|
98
|
+
# BGR, not RGB: pure red is brighter than pure blue in greyscale
|
|
99
|
+
assert int(first.data[0, 0]) > int(second.data[0, 0])
|
|
100
|
+
assert first.start is None and first.exposure_time is None
|
|
101
|
+
assert fake.released.wait(1.0)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@pytest.mark.asyncio
|
|
105
|
+
async def test_frames_keeps_colour_as_rgb(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
106
|
+
fake = FakeCapture([_bgr(1, 2, 3)] * 10)
|
|
107
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
108
|
+
camera = v4lCamera(color=True)
|
|
109
|
+
|
|
110
|
+
iterator = camera.frames()
|
|
111
|
+
frame = await anext(iterator)
|
|
112
|
+
await iterator.aclose()
|
|
113
|
+
|
|
114
|
+
assert frame.data.shape == (2, 3, 3)
|
|
115
|
+
assert tuple(frame.data[0, 0]) == (3, 2, 1)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
async def test_frames_raises_on_failed_read(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
120
|
+
fake = FakeCapture([])
|
|
121
|
+
monkeypatch.setattr(cv2, "VideoCapture", lambda device: fake)
|
|
122
|
+
camera = v4lCamera()
|
|
123
|
+
|
|
124
|
+
iterator = camera.frames()
|
|
125
|
+
with pytest.raises(RuntimeError, match="Could not read frame"):
|
|
126
|
+
await anext(iterator)
|
|
127
|
+
assert fake.released.wait(1.0)
|
|
@@ -2340,7 +2340,7 @@ wheels = [
|
|
|
2340
2340
|
|
|
2341
2341
|
[[package]]
|
|
2342
2342
|
name = "pyobs-core"
|
|
2343
|
-
version = "2.
|
|
2343
|
+
version = "2.13.1"
|
|
2344
2344
|
source = { registry = "https://pypi.org/simple" }
|
|
2345
2345
|
dependencies = [
|
|
2346
2346
|
{ name = "aiohttp" },
|
|
@@ -2372,9 +2372,9 @@ dependencies = [
|
|
|
2372
2372
|
{ name = "tenacity" },
|
|
2373
2373
|
{ name = "typing-extensions" },
|
|
2374
2374
|
]
|
|
2375
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2375
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b2/43/99e30a5a0e42bc49396b876b945ff8c0b8320141f5dcaea959a329c42eaf/pyobs_core-2.13.1.tar.gz", hash = "sha256:54001d7e096dfec2ab1a90cad5d45d35b0d74a28c679266eb88feb1c4045a34f", size = 450687, upload-time = "2026-09-29T08:48:42.267Z" }
|
|
2376
2376
|
wheels = [
|
|
2377
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2377
|
+
{ url = "https://files.pythonhosted.org/packages/6a/18/c9eab05e2e78ec6554c4166f1decde3f6274ab6529c9459ee796acff9bfc/pyobs_core-2.13.1-py3-none-any.whl", hash = "sha256:3afd1de36f35d87f49baca1ab0360d1a2f36cd313e29027fdb5679c4f52df897", size = 689504, upload-time = "2026-09-29T08:48:40.59Z" },
|
|
2378
2378
|
]
|
|
2379
2379
|
|
|
2380
2380
|
[package.optional-dependencies]
|
|
@@ -2386,7 +2386,7 @@ gui = [
|
|
|
2386
2386
|
|
|
2387
2387
|
[[package]]
|
|
2388
2388
|
name = "pyobs-v4l"
|
|
2389
|
-
version = "2.
|
|
2389
|
+
version = "2.1.0"
|
|
2390
2390
|
source = { editable = "." }
|
|
2391
2391
|
dependencies = [
|
|
2392
2392
|
{ name = "opencv-python" },
|
|
@@ -2411,8 +2411,8 @@ dev = [
|
|
|
2411
2411
|
[package.metadata]
|
|
2412
2412
|
requires-dist = [
|
|
2413
2413
|
{ name = "opencv-python", specifier = ">=4.0,<6" },
|
|
2414
|
-
{ name = "pyobs-core", specifier = ">=2.
|
|
2415
|
-
{ name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.
|
|
2414
|
+
{ name = "pyobs-core", specifier = ">=2.13.1,<3" },
|
|
2415
|
+
{ name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.13.1,<3" },
|
|
2416
2416
|
]
|
|
2417
2417
|
provides-extras = ["gui"]
|
|
2418
2418
|
|
|
@@ -2437,21 +2437,21 @@ wheels = [
|
|
|
2437
2437
|
|
|
2438
2438
|
[[package]]
|
|
2439
2439
|
name = "pyrefly"
|
|
2440
|
-
version = "1.
|
|
2440
|
+
version = "1.3.1"
|
|
2441
2441
|
source = { registry = "https://pypi.org/simple" }
|
|
2442
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2442
|
+
sdist = { url = "https://files.pythonhosted.org/packages/4c/7e/082cc1b392318bacfbc087732524f3e089e9e7fe45b7645c4649b6f1f1e9/pyrefly-1.3.1.tar.gz", hash = "sha256:b774f1dfac82867fc16fe2175d80a630e2a72a6835d5b7e492568d6bfb6b05e7", size = 6679145, upload-time = "2026-09-15T05:09:34.49Z" }
|
|
2443
2443
|
wheels = [
|
|
2444
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2445
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2446
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2447
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2448
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2449
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2450
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2451
|
-
{ url = "https://files.pythonhosted.org/packages/5d/
|
|
2452
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2453
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2454
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2444
|
+
{ url = "https://files.pythonhosted.org/packages/6b/bc/f09b5bd7eed796349bd93627aa2c3086df7ed0a114dafc3d2b2841599ee7/pyrefly-1.3.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:0a2a7dfed824fb066aa8a7c8d856c152b98e998fb84b954d5f892fb9834c0bd1", size = 15090117, upload-time = "2026-09-15T05:08:58.477Z" },
|
|
2445
|
+
{ url = "https://files.pythonhosted.org/packages/78/24/a31e7de8e0f310c9f0753826d0df8b6a8ff86793941a6bd88ba24b735633/pyrefly-1.3.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:37a1a1fb41e7190fe3964a877875dd809d6ee2887809e2c3d6e5f25a69805bfd", size = 14430773, upload-time = "2026-09-15T05:09:01.67Z" },
|
|
2446
|
+
{ url = "https://files.pythonhosted.org/packages/75/e1/022352beb186f36d6213a95a975c42676ee418ff5e730629378d25564c5e/pyrefly-1.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:45b7650bc651a5a784701f2fb4f579da9a421c4d1b5fd91f9048f4529e46093c", size = 14877762, upload-time = "2026-09-15T05:09:04.767Z" },
|
|
2447
|
+
{ url = "https://files.pythonhosted.org/packages/19/2c/d62a1b445aad1fd46375b83393b8a67da53883aeeba73d269ce71b3e8fd1/pyrefly-1.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ad57f38bc73679c14a5f62995a2bd3bc43649b7270c858487e2eab78a6f95362", size = 16118225, upload-time = "2026-09-15T05:09:07.828Z" },
|
|
2448
|
+
{ url = "https://files.pythonhosted.org/packages/32/67/3c3fa8a13e3ce8d8322ffb3627255a41a52261f17793e1a24e9214f10857/pyrefly-1.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3506b1252e9f5d755d0693c5a46d46b85579d36534f6e22a41eb8e098d0dde90", size = 16051197, upload-time = "2026-09-15T05:09:10.81Z" },
|
|
2449
|
+
{ url = "https://files.pythonhosted.org/packages/19/d1/84f81b9e32288b5d11c75e006f67e0f6b78b85da575673bd1a21524c8172/pyrefly-1.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39d5a17c1ad655e5f93a6e8e0be90b8db28c6015fe07d6ed4e054891c9e14ef8", size = 15440062, upload-time = "2026-09-15T05:09:14.641Z" },
|
|
2450
|
+
{ url = "https://files.pythonhosted.org/packages/46/3c/2aa0c5ad6a2957a728bb38cfab70d1e9cafad21b0b1c1d92df74a3cf22bd/pyrefly-1.3.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:c61e9dcf888beb81ca0e0c60ea4442640fdcf2f1f65bfe3d9f5d89b85516eb03", size = 14898534, upload-time = "2026-09-15T05:09:17.823Z" },
|
|
2451
|
+
{ url = "https://files.pythonhosted.org/packages/03/5d/2974f249fb2e285f966485719d977c5a2248cc4866403af94d935775ff15/pyrefly-1.3.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a78eed1c53f37807f0e2997be8edbe833b91eb9915f2cb553a1bdcd599e7105c", size = 15477758, upload-time = "2026-09-15T05:09:20.964Z" },
|
|
2452
|
+
{ url = "https://files.pythonhosted.org/packages/68/79/d31f8f0abf5b0610ec24183286ee8a1ee5b76c9aaaa91091399d7e1aaf60/pyrefly-1.3.1-py3-none-win32.whl", hash = "sha256:ea0d0349f1bc80fe8e00a7b3640e40db7486398b685f87b9bd5d2207063668f0", size = 14133005, upload-time = "2026-09-15T05:09:25.03Z" },
|
|
2453
|
+
{ url = "https://files.pythonhosted.org/packages/3f/23/1859f47f536314755d80c4ec2a76d2698435ae8b73604bcd1dfa57ecb39b/pyrefly-1.3.1-py3-none-win_amd64.whl", hash = "sha256:4c24e7d99df9237916c33be23714219a7c8eaf22bad2ac0c3e1d45adcf7df8fb", size = 15066557, upload-time = "2026-09-15T05:09:28.265Z" },
|
|
2454
|
+
{ url = "https://files.pythonhosted.org/packages/92/2a/73e3721921c2bb2c950a9f8c362ee5e2367556b5d4416eb4f8f88503e66f/pyrefly-1.3.1-py3-none-win_arm64.whl", hash = "sha256:1ed85e2b957a78e93353125d890ce3668ce450e49b74025a15c87b6e8ec7f3d1", size = 14348209, upload-time = "2026-09-15T05:09:31.422Z" },
|
|
2455
2455
|
]
|
|
2456
2456
|
|
|
2457
2457
|
[[package]]
|
|
@@ -2734,27 +2734,27 @@ wheels = [
|
|
|
2734
2734
|
|
|
2735
2735
|
[[package]]
|
|
2736
2736
|
name = "ruff"
|
|
2737
|
-
version = "0.16.
|
|
2738
|
-
source = { registry = "https://pypi.org/simple" }
|
|
2739
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2740
|
-
wheels = [
|
|
2741
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2742
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2743
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2744
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2745
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2746
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2747
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2748
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2749
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2750
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2751
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2752
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2753
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2754
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2755
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2756
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2757
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2737
|
+
version = "0.16.8"
|
|
2738
|
+
source = { registry = "https://pypi.org/simple" }
|
|
2739
|
+
sdist = { url = "https://files.pythonhosted.org/packages/ba/78/449cb84790bd5cc3823b2652ee405a4558856e5c4195aee3a16bf7b3eb5d/ruff-0.16.8.tar.gz", hash = "sha256:9247bf92b5f04d825c8639a4fe423ec2e4222acd9222e58412b0dab7e442798b", size = 4938814, upload-time = "2026-09-16T15:54:46.688Z" }
|
|
2740
|
+
wheels = [
|
|
2741
|
+
{ url = "https://files.pythonhosted.org/packages/ac/25/6071aabc530e9be7e2c195e8fe3f7aea2735405b6cf447212832d7811831/ruff-0.16.8-py3-none-linux_armv6l.whl", hash = "sha256:6ffbd6d87383c1edf5f6fa890f10200950240d7c1a16052a19a09d3a2307dd38", size = 10048966, upload-time = "2026-09-16T15:53:57.605Z" },
|
|
2742
|
+
{ url = "https://files.pythonhosted.org/packages/54/98/07f90ecbc74dd5fb5764f11f2bc774d6a7cffef92d2ff5f5b4e9e23c754e/ruff-0.16.8-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:42ed6b878ed61e3acca92f2730a17acff39286944ea82398544696366a6f925e", size = 10165498, upload-time = "2026-09-16T15:54:01.14Z" },
|
|
2743
|
+
{ url = "https://files.pythonhosted.org/packages/fe/1f/e6a712e3b47cad4a40600134105ed193cb773f618a42eb7ba323cb812cc0/ruff-0.16.8-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7ea781c7f2afba8c6a505ea0fb3f994020249e0c450635f5381286fea6b46170", size = 9830004, upload-time = "2026-09-16T15:54:03.998Z" },
|
|
2744
|
+
{ url = "https://files.pythonhosted.org/packages/23/f2/311a08776d75d81c7676e20b6b020ae63cbe881fcdc7a8dd64e6e18bdd93/ruff-0.16.8-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8efeae3bbe414a5efefda11a792dfb51ef90ac48d50c4830de2f644caf3e8659", size = 9986558, upload-time = "2026-09-16T15:54:06.804Z" },
|
|
2745
|
+
{ url = "https://files.pythonhosted.org/packages/f3/ed/37b6cb3d3ba8c73e68ae3eb1d502383beb5aa05a582bb7bb3a922f929f54/ruff-0.16.8-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3a79b795469fef7fc6e908b218eed2eb17332afd85031db6480dc864560e69b2", size = 9877332, upload-time = "2026-09-16T15:54:09.552Z" },
|
|
2746
|
+
{ url = "https://files.pythonhosted.org/packages/22/cc/40873a8f36ad084cc540d55fcca7077264d5b13b24659e9180c176fb2b08/ruff-0.16.8-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3fdc5563cdc50555e6fba39322850860e9267c1b3d12c26a74729d8604c3c812", size = 10507125, upload-time = "2026-09-16T15:54:12.152Z" },
|
|
2747
|
+
{ url = "https://files.pythonhosted.org/packages/c3/e4/fc91a642b78ccbab6b9477720f3644ae7a10a9bcce69a934679cd64f62bc/ruff-0.16.8-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:34508983c70665578dab88f5223d8e6228307e1135398ca8bfc8b7e9501e282b", size = 11336694, upload-time = "2026-09-16T15:54:15.489Z" },
|
|
2748
|
+
{ url = "https://files.pythonhosted.org/packages/c2/3d/bbd2a9a600a4e73dc3e7548a249c8d1671273464b55822c6fae50f602dff/ruff-0.16.8-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:644bb578569e0ffc575741232bd385dacdd6fbe123f1a729e7a225f54aa3957f", size = 10774448, upload-time = "2026-09-16T15:54:18.16Z" },
|
|
2749
|
+
{ url = "https://files.pythonhosted.org/packages/1a/41/d83af9879a7b6e8bf5fe16b1da0b134049d2f5d3afac12defb0897cb84bd/ruff-0.16.8-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:15e7d226246961db9235098333caa13063906d3851136b84c2900b82f5daa1df", size = 10323796, upload-time = "2026-09-16T15:54:20.743Z" },
|
|
2750
|
+
{ url = "https://files.pythonhosted.org/packages/f5/2c/cefd07bfe914b84943ea769ade8d607bd22750b965d3228eefd7cebd15d0/ruff-0.16.8-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:a2bf6bc3e9ebdd4449abc6f06cf64b98051a2c61cf94d2fe9596518c881f1a1e", size = 10514115, upload-time = "2026-09-16T15:54:23.497Z" },
|
|
2751
|
+
{ url = "https://files.pythonhosted.org/packages/f3/9d/76a2e26c79a23be6e6e3664c57bec9e9fc8de155cfb9e4b67ea91b64f9d7/ruff-0.16.8-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:6ca111ba0849539165e9e59d2b442542f3c1e8060ebbdea82494f1ffbccb1e1f", size = 10072582, upload-time = "2026-09-16T15:54:26.185Z" },
|
|
2752
|
+
{ url = "https://files.pythonhosted.org/packages/2e/d4/f42edddb39668af1a559ceafa3823aedd65633a48dc9768e775485faa2c1/ruff-0.16.8-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:359a1e5b495448ee1e91018064382ebc86f90e8aac2fed222c7d0e4e8df85fd2", size = 9879644, upload-time = "2026-09-16T15:54:29.278Z" },
|
|
2753
|
+
{ url = "https://files.pythonhosted.org/packages/f8/d4/913e3195d95e0378786c6656945c865f534a3560e29139da4882aff630d1/ruff-0.16.8-py3-none-musllinux_1_2_i686.whl", hash = "sha256:59e8f5681349474110b24d62e93cfda6593f5fa3473446ca3705200cac1a08b9", size = 10231569, upload-time = "2026-09-16T15:54:32.036Z" },
|
|
2754
|
+
{ url = "https://files.pythonhosted.org/packages/2b/c4/8aa6ea0bdcedbd1bf87397e2fc4ed8406448ea5842f8660bc6e5f163039d/ruff-0.16.8-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:efa3e7a16d1baaa79957888dfdf8be9ef2e44db81cb032af06d76632ab59e773", size = 10663666, upload-time = "2026-09-16T15:54:34.838Z" },
|
|
2755
|
+
{ url = "https://files.pythonhosted.org/packages/3d/02/7f10ef4700bc223c30a3fdd10631a29830c45524b810a3c7ed947af64591/ruff-0.16.8-py3-none-win32.whl", hash = "sha256:55793ba85c69921e89be061426d91a78652d6e50317c962240922747a4eb713f", size = 10093472, upload-time = "2026-09-16T15:54:37.47Z" },
|
|
2756
|
+
{ url = "https://files.pythonhosted.org/packages/1e/5d/a509c07d714b6da88f2c518b4637cf6f1d46b074be8f0f1e5fb9ff5126fe/ruff-0.16.8-py3-none-win_amd64.whl", hash = "sha256:a6b85621fd3c81e31fc5f5add09c9c078b430db3595ca632efafdec9e64ebfaa", size = 10586899, upload-time = "2026-09-16T15:54:40.488Z" },
|
|
2757
|
+
{ url = "https://files.pythonhosted.org/packages/fe/a0/50787329e4f20bf9dc9f6230015d46ec69c51a97ace5bc202dae4755365d/ruff-0.16.8-py3-none-win_arm64.whl", hash = "sha256:d075e820af612102ce217f07cc93e69f9490b10ec13ea85fa87bd03d996cef8a", size = 10386316, upload-time = "2026-09-16T15:54:43.332Z" },
|
|
2758
2758
|
]
|
|
2759
2759
|
|
|
2760
2760
|
[[package]]
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import logging
|
|
3
|
-
import threading
|
|
4
|
-
import time
|
|
5
|
-
from collections.abc import Callable
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
import cv2
|
|
9
|
-
from pyobs.modules.camera import BaseVideo
|
|
10
|
-
|
|
11
|
-
log = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
# cv2's V4L2 backend calls are blocking and are made directly on the event loop thread (see
|
|
14
|
-
# _run_blocking). If the camera has gone unresponsive, they can hang indefinitely, so they're
|
|
15
|
-
# bounded with a timeout rather than let a single dead camera freeze the whole module.
|
|
16
|
-
_SDK_CALL_TIMEOUT = 5.0
|
|
17
|
-
|
|
18
|
-
# read() waits for the next frame, which can legitimately take a while depending on the camera's
|
|
19
|
-
# own frame rate -- a more generous timeout than _SDK_CALL_TIMEOUT so normal operation never trips it.
|
|
20
|
-
_FRAME_WAIT_TIMEOUT = 30.0
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class v4lCamera(BaseVideo):
|
|
24
|
-
def __init__(self, device: int = 0, **kwargs: Any):
|
|
25
|
-
BaseVideo.__init__(self, **kwargs)
|
|
26
|
-
|
|
27
|
-
# store
|
|
28
|
-
self._device = device
|
|
29
|
-
|
|
30
|
-
# thread
|
|
31
|
-
self.add_background_task(self._capture)
|
|
32
|
-
|
|
33
|
-
@staticmethod
|
|
34
|
-
async def _run_blocking(func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT) -> bool:
|
|
35
|
-
"""Run a blocking cv2/V4L2 call in a daemon thread, so a hung call can't freeze the module.
|
|
36
|
-
|
|
37
|
-
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
38
|
-
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
True if func completed within timeout, False if it's still running in the background.
|
|
42
|
-
"""
|
|
43
|
-
loop = asyncio.get_running_loop()
|
|
44
|
-
future: asyncio.Future[None] = loop.create_future()
|
|
45
|
-
|
|
46
|
-
def _finish() -> None:
|
|
47
|
-
# wait_for cancels the future on timeout, so guard set_result to avoid an
|
|
48
|
-
# InvalidStateError from the loop thread once the orphaned call finally ends.
|
|
49
|
-
if not future.done():
|
|
50
|
-
future.set_result(None)
|
|
51
|
-
|
|
52
|
-
def _wrapper() -> None:
|
|
53
|
-
try:
|
|
54
|
-
func()
|
|
55
|
-
finally:
|
|
56
|
-
loop.call_soon_threadsafe(_finish)
|
|
57
|
-
|
|
58
|
-
threading.Thread(target=_wrapper, daemon=True).start()
|
|
59
|
-
try:
|
|
60
|
-
await asyncio.wait_for(future, timeout=timeout)
|
|
61
|
-
return True
|
|
62
|
-
except TimeoutError:
|
|
63
|
-
return False
|
|
64
|
-
|
|
65
|
-
async def _open_camera(self) -> Any:
|
|
66
|
-
"""Open the V4L2 camera device, without blocking the event loop."""
|
|
67
|
-
result: list[Any] = []
|
|
68
|
-
lock = threading.Lock()
|
|
69
|
-
timed_out = False
|
|
70
|
-
|
|
71
|
-
def _open() -> None:
|
|
72
|
-
camera = cv2.VideoCapture(self._device)
|
|
73
|
-
with lock:
|
|
74
|
-
if timed_out:
|
|
75
|
-
# timed out while still opening; release the handle nobody will use
|
|
76
|
-
camera.release()
|
|
77
|
-
else:
|
|
78
|
-
result.append(camera)
|
|
79
|
-
|
|
80
|
-
if not await self._run_blocking(_open):
|
|
81
|
-
with lock:
|
|
82
|
-
timed_out = True
|
|
83
|
-
if result:
|
|
84
|
-
result.pop().release()
|
|
85
|
-
raise TimeoutError(f"Timed out opening camera device after {_SDK_CALL_TIMEOUT}s.")
|
|
86
|
-
return result[0]
|
|
87
|
-
|
|
88
|
-
async def _read_frame(self, camera: Any) -> Any:
|
|
89
|
-
"""Read the next frame from the camera, without blocking the event loop.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
The next frame, or None if the read timed out.
|
|
93
|
-
"""
|
|
94
|
-
result: list[Any] = []
|
|
95
|
-
|
|
96
|
-
def _read() -> None:
|
|
97
|
-
_, frame = camera.read()
|
|
98
|
-
result.append(frame)
|
|
99
|
-
|
|
100
|
-
if not await self._run_blocking(_read, timeout=_FRAME_WAIT_TIMEOUT):
|
|
101
|
-
log.error("Timed out reading frame after %.1fs.", _FRAME_WAIT_TIMEOUT)
|
|
102
|
-
return None
|
|
103
|
-
return result[0]
|
|
104
|
-
|
|
105
|
-
async def _capture(self) -> None:
|
|
106
|
-
# open camera
|
|
107
|
-
camera = await self._open_camera()
|
|
108
|
-
|
|
109
|
-
# loop until the background task is cancelled on close
|
|
110
|
-
last = time.time()
|
|
111
|
-
try:
|
|
112
|
-
while True:
|
|
113
|
-
# read frame
|
|
114
|
-
frame = await self._read_frame(camera)
|
|
115
|
-
if frame is None:
|
|
116
|
-
continue
|
|
117
|
-
|
|
118
|
-
# if time since last image is too short, wait a little
|
|
119
|
-
if time.time() - last < self._interval:
|
|
120
|
-
await asyncio.sleep(0.01)
|
|
121
|
-
continue
|
|
122
|
-
last = time.time()
|
|
123
|
-
|
|
124
|
-
# process it
|
|
125
|
-
await self._set_image(frame)
|
|
126
|
-
finally:
|
|
127
|
-
# release camera
|
|
128
|
-
camera.release()
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
__all__ = ["v4lCamera"]
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Unit tests for the non-hardware logic in v4lCamera: constructor state and the
|
|
2
|
-
_run_blocking timeout wrapper.
|
|
3
|
-
|
|
4
|
-
Opening the V4L2 device and reading frames is out of scope here.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import asyncio
|
|
8
|
-
import threading
|
|
9
|
-
|
|
10
|
-
import pytest
|
|
11
|
-
|
|
12
|
-
from pyobs_v4l import v4lCamera
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_constructor_defaults() -> None:
|
|
16
|
-
camera = v4lCamera()
|
|
17
|
-
assert camera._device == 0
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def test_constructor_device() -> None:
|
|
21
|
-
camera = v4lCamera(device=3)
|
|
22
|
-
assert camera._device == 3
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@pytest.mark.asyncio
|
|
26
|
-
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
27
|
-
ran: list[bool] = []
|
|
28
|
-
|
|
29
|
-
def fast() -> None:
|
|
30
|
-
ran.append(True)
|
|
31
|
-
|
|
32
|
-
assert await v4lCamera._run_blocking(fast) is True
|
|
33
|
-
assert ran == [True]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@pytest.mark.asyncio
|
|
37
|
-
async def test_run_blocking_times_out() -> None:
|
|
38
|
-
done = threading.Event()
|
|
39
|
-
|
|
40
|
-
def slow() -> None:
|
|
41
|
-
done.wait()
|
|
42
|
-
|
|
43
|
-
assert await v4lCamera._run_blocking(slow, timeout=0.01) is False
|
|
44
|
-
done.set()
|
|
45
|
-
await asyncio.sleep(0.05) # let the daemon thread drain before the loop closes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|